Issue
I am trying to make a very simple button in XML with a drawable. The problem is it does not show up at all.
Here is the drawable code:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/listview_background_shape">
<stroke android:width="2dp" android:color="#ff207d94" />
<padding android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp" />
<corners android:radius="5dp" />
<solid android:color="#ffffffff" />
</shape>
</selector>
And here is the very simple test activity:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@color/black"
tools:context="com.vroy.trapper.testactivity">
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:background="@drawable/simple_rect_btn"
android:text="Test Button"
android:id="@+id/test"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Only the text in the button shows.
What very simple mistake am I making?
Solution
use tag item as the direct child of the selector tag
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/listview_background_shape">
<stroke android:width="2dp" android:color="#ff207d94" />
<padding android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp" />
<corners android:radius="5dp" />
<solid android:color="#ffffffff" />
</shape>
</item>
</selector>
Answered By - Pip
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.