3

我对 Android Studio 很陌生。作为初学者,我创建了一个简单的应用程序,仅用于测试目的并查看 Android Studio Material 主题的外观。我目前正在使用最新版本,即。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" >

是否有任何其他可能从默认的天蓝色更改为绿色或黄色或紫色?

Android Studio 默认颜色

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

我怎么能这样做?

4

2 回答 2

12

第一种方法:

在 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 Studio 中,它可以从默认的天蓝色更改为任何其他颜色,如粉红色或绿色!

第二种方法:

在 xml 下创建 3 个文件,即。res/xml,例如checked.xml、unchecked.xml和custom_checkbox.xml

检查.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>

未选中的.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>

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

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

于 2014-07-24T05:47:20.687 回答
7

同样在带有 AppCompat 的 v23 中,您可以使用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"
    />

在 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>
于 2016-02-18T15:48:25.943 回答