I'm trying to get this shape done in xml:
What I have tried:
<item>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/res_pressed"/>
<item
android:drawable="@color/res_default"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
android:left="15dp"/>
</layer-list>
</item>
Still I can't get it right with round and straight corners for the yellow shape.
You need to use a shape
drawable so you can add a corners tag. Try
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/res_pressed" />
<corners android:topLeft="10dp" android:bottomLeft="10dp" />
</shape>
</item>
<item
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
android:left="15dp">
<shape android:shape="rectangle">
<solid android:color="@color/res_default" />
<corners android:topRight="10dp" android:bottomRight="10dp" />
</shape>
</item>
</layer-list>
This is a workaround:
Create top.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorPrimaryDark" />
<corners
android:radius="15dp"/>
</shape>
Create bot.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorAccent" />
<corners android:radius="15dp" />
</shape>
The desired shape:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/bot" />
<item
android:bottom="0dp"
android:drawable="@drawable/top"
android:left="15dp"
android:right="0dp"
android:top="0dp"/>
</layer-list>
Try this, identical to Gabe Sechan
post but with few modifications..
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="20dp"
>
<shape android:shape="rectangle">
<solid android:color="@color/yellow"/>
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="0dp"
android:topLeftRadius="10dp"
android:topRightRadius="0dp"
/>
</shape>
</item>
<item
android:bottom="0dp"
android:left="15dp"
android:right="0dp"
android:top="0dp">
<shape android:shape="rectangle">
<solid android:color="@color/blue"/>
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="0dp"
android:topRightRadius="10dp"/>
</shape>
</item>
</layer-list>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.