Android How to install 2 xml for LinearLayout

I installed xml for this LinearLayout and 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 the 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" > 

in this step, I want to add a border around this LinearLayout, I created another 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 item?

+6
source share
1 answer

You cannot apply two drawings to the layout, but you can achieve your requirement using only disposable ones.

 <?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> 
+1
source

Source: https://habr.com/ru/post/979602/


All Articles