Change <layer-item> items by Java code

前端 未结 3 1587
谎友^
谎友^ 2021-01-12 17:30

I have the following XML:





        
相关标签:
3条回答
  • 2021-01-12 17:50

    Assuming that you want to have access to them through Java code after they are loaded as a Drawable in your app, you should be able to do something like the following:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        final LayerDrawable ld = (LayerDrawable) getResources().getDrawable(R.drawable.my_drawable);
        final ClipDrawable d1 = (ClipDrawable) ld.findDrawableByLayerId(R.id.customPlayerProgress);
        final ClipDrawable d2 = (ClipDrawable) ld.findDrawableByLayerId(R.id.customPlayerProgressSecondary);
    
        /* modify ld, d1 and d2 by calling their methods here */
    }
    

    Also look at this for some more ideas.

    0 讨论(0)
  • 2021-01-12 18:03

    You may be familiar with DOM. You just need to modify the change and then save the file.

    Here is an article that may be of some assistance.

    0 讨论(0)
  • 2021-01-12 18:06

    You can't change generated XML files at run-time.

    0 讨论(0)
提交回复
热议问题