我们来模仿实现微信的聊天输入框:
先设置绿色的背景:
<?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="@android:color/holo_green_light" /> </shape> </item></layer-list>
再叠加一层白色,留出侧面绿色线条的高度: <?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="@android:color/holo_green_light" /> </shape> </item> <item android:bottom="8dp"> <shape android:shape="rectangle"> <solid android:color="@android:color/white" /> </shape> </item>
</layer-list>
再铺上一层白色,覆盖已经设置好的背景,留出底部和侧面的线条,中间的一层其实就是为了留出两边的绿色线框的高度: <?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="@android:color/holo_green_light" /> </shape> </item> <item android:bottom="8dp"> <shape android:shape="rectangle"> <solid android:color="@android:color/white" /> </shape> </item> <item android:bottom="1dp" android:left="1dp" android:right="1dp" android:shape="rectangle"> <shape> <solid android:color="@android:color/white" /> </shape> </item> </layer-list>