我一直在寻找在单个shapes.xml中定义不同形状的可能性,并在某些特定事件中引用每个形状.
<?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>
将其应用于样式中的background属性.通过将级别设置为该元素,可以实现不同形状的交换.
例如:findViewById(R.id.mybutton).getBackground().setLevel(1);
在上面的代码中,我将第二个形状设置为id为mybutton的按钮.
解决方法
<?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>
你可以将它用于寄宿生和任何形状..以供参考……”如果它有用,那么接受答案并投票给答案
原文地址:https://www.jb51.cc/android/314803.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。