将默认设计主题更改为自定义颜色

Ach*_*ver 3 android android-checkbox android-styles material-design

我是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>
Run Code Online (Sandbox Code Playgroud)

在Android Studio Manifest.xml中,

android:theme="@style/CustomTheme" >
Run Code Online (Sandbox Code Playgroud)

还有其他可能从默认天蓝色变为绿色或黄色或紫色吗?

Android Studio默认颜色

有没有其他方法可以将默认天蓝色主题更改为其他颜色,如粉红色或绿色?

我想学习,所以请给我一些关于如何做到这一点的建议?

Ach*_*ver 10

第一种方法:

在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>
Run Code Online (Sandbox Code Playgroud)

第一种方法:粉红色

第一种方法:绿色

上面的代码很简单,运行良好.在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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

从上面的第二种方法,它(自定义文件)也可以根据我们的要求创建任何形状和颜色.甚至我们也可以使用第二种方法自定义小部件的样式,形状和主题.

以上两种方法对我来说都很好!


小智 7

另外在v23中使用AppCompat,您可以使用android.support.v7.widget.AppCompatCheckBox并更改CheckBox样式,如下所示:

<android.support.v7.widget.AppCompatCheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:theme="@style/CheckBox"
    />
Run Code Online (Sandbox Code Playgroud)

在style.xml中的位置:

<style name="CheckBox" parent="Widget.AppCompat.CompoundButton.CheckBox">
    <item name="colorControlNormal">@color/checkbox_normal</item> <!-- border color -->
    <item name="colorControlActivated">@color/checkbox_activated</item> <!-- fill color -->
    <item name="colorControlHighlight">@color/checkbox_highlight</item> <!-- animation color -->
</style>
Run Code Online (Sandbox Code Playgroud)