Reputation: 11529
I'm wondering if it's possible to build a custom button layout with different appearance depending on state so it acts like a button. For example, a LinearLayout with an ImageView and TextView, with these states.
When the button is in normal state, display image_normal.png
and text in red.
When the button is pressed, display image_pressed.png
, background red and text in white.
When the button is disabled, display image_disabled.png
and text in grey.
Thank you!
Upvotes: 0
Views: 237
Reputation: 38605
Any view can have any background and any view can be made clickable, so there is nothing preventing you from having a LinearLayout
with the background you described. It's worth noting that you don't need a LinearLayout
to have an image next to text, you can use the fact that TextView
supports drawables on any side of the text using the drawable[Left|Top|Right|Bottom]
attributes.
If your question is about the syntax of a selector
drawable, I would refer you to the documentation. Note that Android evaluates states top to bottom, so choose the order wisely. The last item should be the "default" state when none of the ones above apply. For the example you gave, you would probably have something like
<selector>
<item android:state_pressed="true" android:drawable="..." />
<item android:state_enabled="true" android:drawable="..." />
<item android:drawable="..." /> <!-- disabled -->
</selector>
Upvotes: 1