Multipe form inside shape.xml in android

I was looking for opportunities to define different shapes inside the same shape.xml and refer to each of them on some specific events.

I finally found a solution to my question. And the answer is to use a list-level.

<?xml version="1.0" encoding="utf-8"?> <level-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:maxLevel="0"> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">   <gradient android:startColor="#aaa" android:endColor="#eee" android:angle="270" />    <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" android:topLeftRadius="7dp" android:topRightRadius="7dp" /> </shape> </item> <item android:maxLevel="1"> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">   <gradient android:startColor="#eee" android:centerColor="#ddd" android:endColor="#00fff2" android:angle="270" />    <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" android:topLeftRadius="7dp" android:topRightRadius="7dp" /> </shape> </item> </level-list> 

Apply this to the background attribute in the style. Change between different forms can be achieved by setting the level on this element.

For example: findViewById(R.id.mybutton).getBackground().setLevel(1);

In the above code, I set the second shape to the button with id mybutton.

+7
source share
1 answer
 <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <stroke android:width="1dip" android:color="#FF8000" /> <solid android:color="#00FFFFFF" android:paddingLeft="10dip" android:paddingTop="10dip"/> <corners android:radius="10px"/> <padding android:left="10dip" android:top="10dip" android:right="10dip" android:bottom="10dip" /> </shape> 

you can use this for Boarder and any form .. for reference ... '' If this is useful, accept the answer and vote for the answer

0
source

All Articles