Reputation: 3805
I've got the following button:
<Button
android:id="@+id/searchCompaniesButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/company_icon"
android:drawablePadding="10dp"
android:drawableRight="@drawable/next_icon_big"
android:gravity="left|center_vertical"
android:paddingLeft="10dp"
android:backgroud="@drawable/transparent_button_selector"
android:paddingRight="10dp"
android:text="@string/searchCompanies" />
transparent_button_selector
is transparent_button_selector.xml
in /drawable-ldpi folder:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/lightGrey"
android:state_pressed="true" />
<item android:drawable="@color/veryLightGrey"
android:state_focused="true" />
<item android:drawable="@null" />
</selector>
Also I've got a colors.xml
:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="lightGrey">#3d3d3d</color>
<color name="veryLightGrey">#4d4d4d</color>
</resources>
But when I run my app, log will say:
'item' tag requires a 'drawable' attribute"
What the hell? I know there are few similar questions, but answers are not helpful. I tried:
Upvotes: 3
Views: 3235
Reputation: 5643
If a selector
is used to show which items in a list are currently picked then the best answer simply:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/activated_color" android:state_activated="true"/>
</selector>
Picked items are then determined by the isActivated
state if the view.
Why is a transparent background better than the more more direct statement of "no background"?
Upvotes: 0
Reputation: 29
Your android:background
attribute is misspelled:
android:backgroud="@drawable/transparent_button_selector"
The letter 'n' is missing in 'background'
Upvotes: 0
Reputation: 390
The drawable attribute always takes @drawable.i.e you have to replace
<item android:drawable="@color/..."
android:state_pressed="true" />
with
<item android:drawable="@drawable/..."
android:state_pressed="true" />
Use this,
<item
android:state_pressed="true"
android:drawable="@drawable/selected_state" />
Then make a shape in drawable folder with name "selected_state" like this.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/lightGrey" />
</shape>
Upvotes: 0
Reputation: 653
Replace this:
<item android:drawable="@null" />
with:
<item android:drawable="@color/transparent" />
and add transparent color in your color file with code: #00000000
Upvotes: 16