Reputation: 191
Actually I have this code:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid
android:color="#ffffff" />
<stroke
android:width="0.5dp"
android:color="#000000" />
</shape>
It creates a border around a view but I want only make a border in top and bottom.
How?
EDIT: Sorry, I forgot it should work with state pressed
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@color/color" />
</selector>
Upvotes: 0
Views: 109
Reputation: 133560
Try this
bkg.xml in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#FF0000" />
</shape>
</item>
<item android:bottom="5dp" android:top="5dp" >
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
</layer-list>
Change the color and the stroke width according to your requirements.
Snap Shot of graphical editor
Edit: To the question in the comment
Define itembkg. xml as below
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/bkg" />
// bkg.xml in drawable folder
// drawable in pressed state
<item android:state_focused="false"
android:drawable="@drawable/tvnormal" />
// set a different drawable in normal state
</selector>
Then in your view add the below attribute
android:background="@drawable/itembkg"
Upvotes: 1
Reputation: 6027
Try this....
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape android:shape="rectangle">
<padding android:top="1dp"
android:bottom="1dp" />
<solid android:color="#000000"/>
</shape>
</item>
<item >
<shape android:shape="rectangle">
<solid android:color="#ffffff"/>
</shape>
</item>
</layer-list>
Upvotes: 0