Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating State List Drawable XML for Background - Android

I am trying to get the following state list to work. The idea is to create a white background.

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_selected="true"         
android:drawable="@android:color/transparent" /> 
<item android:state_selected="true" android:drawable="@android:color/transparent" /> 
<item android:state_pressed="true" android:state_selected="false"    
android:drawable="@android:color/transparent" /> 
<item android:state_selected="false" android:drawable="@color/WHITE" /> 
</selector>

When I try and compile this I get the following error..

@color/transparent and @color.WHITE don't exist.

Do I need to define these somewhere and if so how ?

Thanks !

like image 900
GuybrushThreepwood Avatar asked May 20 '26 14:05

GuybrushThreepwood


2 Answers

I think the only problem is you are referencing directly a color instead of an actual Drawable. Try creating a ColorDrawable first and use it in your StateListDrawable.

When creating a ColorStateList (which is different from StateListDrawable because it's a list of colors and not Drawables) you can directly use colors ...

like image 166
Cyril Mottier Avatar answered May 22 '26 04:05

Cyril Mottier


You must use @android:color, otherwise it doesn't know where the color is defined.

android:background="@android:color/white"
like image 28
Sea turtle Avatar answered May 22 '26 05:05

Sea turtle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!