Question

I'm working on optimization for my app and I'm trying to replace relatice layout with text and image with only TextView that contains compound drawable. Existing implementation of side menyou has a single image with level for each position. It's much easier to set the same res to compound drawable but is it possible to change level in adapter code ?

Was it helpful?

Solution

to do it via code:

(let's say "text" is your TextView

and "level" is an int with your desired level)

        Drawable[] drawables = text.getCompoundDrawables();
        for (Drawable drawable : drawables) {
            if (drawable != null)
                drawable.setLevel(level);
        }

use this if you are using start/end instead of left/right:

      text.getCompoundDrawablesRelative()

this will change the levels of all the drawables, if you just want one of the don't use the for loop

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top