Skip to content Skip to sidebar Skip to footer

Change Items By Java Code

I have the following XML:

Solution 1:

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:

@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    finalLayerDrawableld= (LayerDrawable) getResources().getDrawable(R.drawable.my_drawable);
    finalClipDrawabled1= (ClipDrawable) ld.findDrawableByLayerId(R.id.customPlayerProgress);
    finalClipDrawabled2= (ClipDrawable) ld.findDrawableByLayerId(R.id.customPlayerProgressSecondary);

    /* modify ld, d1 and d2 by calling their methods here */
}

Also look at this for some more ideas.

Solution 2:

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

Solution 3:

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.

Post a Comment for "Change Items By Java Code"