I would like to define a selector dynamically in java.
I use drawables from ressources and above I write some text. So, both normal drawable and drawable focus state cannot be defined into an xml file...
Is there a way to do this in Java?
Have you checked out StateListDrawable ?
This is the type of drawable that will be created by your selector.
So you could do something like this:
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[]{android.R.attr.state_focused}, mFocusedDrawable);
drawable.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed}, mEnabledPressedDrawable);
drawable.addState(new int[0], mDefaultDrawable);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.