Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android- How to set 2 xml drawable for LinearLayout

I set a xml drawable for this LinearLayout and I want to add another one to it . this is the first xml drawable :

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@color/blue" android:state_pressed="true"/>
    <item android:drawable="@color/blue" android:state_selected="true"/>
    <item android:drawable="@color/white"/>

</selector>

This is xml layout :

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg1"
    android:orientation="vertical" >

at this step ,I want to add a border around this LinearLayout , I've created another drawable layout . this is the 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="3dip" android:color="#B1BCBE" />
    <corners android:radius="10dip"/>
    <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

How can I use these 2 xmles for one element ?

like image 692
mahdi yamani Avatar asked Dec 15 '14 08:12

mahdi yamani


1 Answers

You can not apply two drawable to a layout but you can achieve your requirement using single drawable only.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@color/blue" android:state_pressed="true"/>
<item android:drawable="@color/blue" android:state_selected="true"/>
<item android:drawable="@drawable/name_of_your_second_drawable"/>

</selector>
like image 170
Praveena Avatar answered Oct 02 '22 15:10

Praveena