将默认设计主题更改为自定义颜色 [英] Change default design theme to customized color

查看:132
本文介绍了将默认设计主题更改为自定义颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Android Studio的新手.作为一个初学者,我创建了一个简单的应用程序,仅用于测试目的并查看Android Studio素材主题的外观.我目前正在使用最新版本,即. L预览-Studio 0.8.2版.

I am very new to Android Studio. As a beginner I have created a simple app just for testing purpose and to view the appearance of Android studio material theme. I am currently working with latest version ie. L preview - Studio 0.8.2 version.

在这里,我刚刚创建了textview,edittext,单选按钮和复选框.当我选择男性或女性时,它会显示天蓝色.我可以将天蓝色更改为绿色或黄色吗?

Here, I have just created textview, edittext, radio buttons and checkboxes. When I select male or female, it appears sky blue color. Could I be able to change sky blue color as a green or yellow color?

我不知道它叫什么名字.从图片中可以看到edittext,单选按钮和复选框选中状态为天蓝色.当我尝试单击或选择任何内容时,这些复选框或单选按钮需要从默认颜色更改为其他颜色,例如绿色或黄色!

I do not know what is the name for that. From the picture can able to see edittext, radio buttons and checkboxes selected state as a sky blue color. When I try to click or select anything then those checkboxes or radio buttons need to change from default color to other colors like green or yellow!

在res/values/styles.xml中,

In 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中,

In Android Studio Manifest.xml,

android:theme="@style/CustomTheme" >

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

Is there any other possible to change from default sky blue color to green or yellow or purple?

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

Is there any other way to change default sky blue color theme to other colors like pink or green?

我该怎么办?

推荐答案

第一种方法:

在res/values-v21/styles.xml中,

First Method:

In 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中,它可以从默认的天蓝色变成其他任何颜色,例如粉红色或绿色!

The above code is simple and working well. In Android studio, it could be able to change from default sky blue color to any other colors like pink or green!

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

Create 3 files under xml ie. res/xml such as checked.xml, unchecked.xml and 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>

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

From above second method, it (customized file) also could be able to create any shapes and colors based on our requirements. Even we can be able to customize the style, shapes and themes for a widget by using 2nd method.

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

Above two methods are working fine for me!

这篇关于将默认设计主题更改为自定义颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆