大佬教程收集整理的这篇文章主要介绍了android – 如何为按钮选择器设置不同的主题?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的button_SELEctor.xml
<?xml version="1.0" encoding="utf-8"?> <SELEctor xmlns:android="http://scheR_147_11845@as.android.com/apk/res/android"> <item android:state_pressed="true"> <color android:color="@color/color_theme1"/> </item> <!-- pressed --> <item android:drawable="@color/transparent"/> <!-- default --> </SELEctor>
button_SELEctor.xml:
<?xml version="1.0" encoding="utf-8"?> <SELEctor xmlns:android="http://scheR_147_11845@as.android.com/apk/res/android"> <!--SELEcted/pressed/focused --> <item android:state_SELEcted="true" android:drawable="@drawable/button_SELEcted" /> <item android:drawable="@drawable/button_default"/> <!-- default --> </SELEctor>
button_default.xml:
<?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://scheR_147_11845@as.android.com/apk/res/android" android:shape="rectangle"> <!--this is to give gradient effect --> <gradient android:angle="270" android:startColor="@color/gray" android:endColor="#@color/gray" /> <!-- this will make corners of button rounded --> <corners android:topLefTradius="5dip" android:bottomRighTradius="5dip" android:topRighTradius="5dip" android:bottomLefTradius="5dip"/> </shape>
button_SELEcted.xml:
<?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://scheR_147_11845@as.android.com/apk/res/android" android:shape="rectangle"> <!--this is to give gradient effect --> <gradient android:angle="270" android:startColor="@color/color_priMary" android:endColor="#@color/color_priMary" /> <!-- this wil make corners of button rounded --> <corners android:topLefTradius="5dip" android:bottomRighTradius="5dip" android:topRighTradius="5dip" android:bottomLefTradius="5dip"/> </shape>
button.setOnClickListener(new View.onClickListener() { @Override public void onClick(View v) { if(v.isSELEcted()) { v.setSELEcted(false); } else { v.setSELEcted(true); } } });
以上是大佬教程为你收集整理的android – 如何为按钮选择器设置不同的主题?全部内容,希望文章能够帮你解决android – 如何为按钮选择器设置不同的主题?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。