标签:android android-styles material-design android-checkbox
我是Android Studio的新手.作为初学者,我创建了一个简单的应用程序,仅用于测试目的并查看Android studio材料主题的外观.我目前正在使用最新版本即. L预览 – Studio 0.8.2版本.
在这里,我刚刚创建了textview,edittext,单选按钮和复选框.当我选择男性或女性时,它显示为天蓝色.我可以将天蓝色改为绿色或黄色吗?
我不知道这是什么名字.从图片中可以看到edittext,单选按钮和复选框选中状态为天蓝色.当我尝试单击或选择任何内容时,那些复选框或单选按钮需要从默认颜色更改为其他颜色,如绿色或黄色!
码
在res / values / styles.xml中,
<resources>
<!-- Base application theme. -->
<color name="custom_theme_color">#b0b0ff</color>
<style name="CustomTheme" parent="android:Theme.Material">
<item name="android:colorBackground">@color/custom_theme_color</item>
</style>
</resources>
在Android Studio Manifest.xml中,
android:theme="@style/CustomTheme" >
还有其他可能从默认天蓝色变为绿色或黄色或紫色吗?
有没有其他方法可以将默认天蓝色主题更改为其他颜色,如粉红色或绿色?
我想学习,所以请给我一些关于如何做到这一点的建议?
解决方法:
第一种方法:
在res / values-v21 / styles.xml中,
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
<item name="android:colorAccent">@color/custom_theme_color</item>
<item name="android:colorPrimaryDark">@color/custom_theme_color</item>
<item name="android:colorPrimary">@color/custom_theme_color</item>
</style>
上面的代码很简单,运行良好.在Android工作室中,它可以从默认的天蓝色更改为任何其他颜色,如粉红色或绿色!
第二种方法:
在xml下创建3个文件即. res / xml,例如checked.xml,unchecked.xml和custom_checkbox.xml
checked.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2px" android:color="#FF00FF" />
<size android:height="20dp" android:width="20dp"/>
</shape>
unchecked.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2px" android:color="#ffc0c0c0" />
<size android:height="20dp" android:width="20dp"/>
</shape>
custom_checkbox.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:drawable="@xml/checked" />
<item android:state_pressed="true"
android:drawable="@xml/checked" />
<item android:drawable="@xml/unchecked" />
</selector>
从上面的第二种方法,它(自定义文件)也可以根据我们的要求创建任何形状和颜色.甚至我们也可以使用第二种方法自定义小部件的样式,形状和主题.
以上两种方法对我来说都很好!
标签:android,android-styles,material-design,android-checkbox 来源: https://codeday.me/bug/20190712/1443698.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。