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

标签 android material-design android-styles android-checkbox

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

在这里,我刚刚创建了 TextView 、编辑文本、单选按钮和复选框。当我选择男性或女性时,它会出现天蓝色。我可以将天蓝色更改为绿色或黄色吗?

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

代码

在 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 default color

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

我该怎么做?

最佳答案

第一种方法:

在 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>

First Method : Pink color

First Method: Green color

上面的代码很简单并且运行良好。在 Android Studio 中,它可以从默认的天蓝色更改为任何其他颜色,例如粉红色或绿色!

第二种方法:

在xml ie下创建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 - 将默认设计主题更改为自定义颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24902738/

相关文章:

java - LibGDX 3D 提高性能

android - 在较新的 Android 设备中显示旧版菜单

java - 无法在 onSaveInstanceState 中 bundle 数据

android - SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR 不适用于 API 28

android - 如何更改我的其中一个 EditText 的文本选择 handle 的颜色?

android - 是否可以在大文本通知中将扩展通知设置为默认值?

android - 在 ImageView 中选择 Fling 和 Drag 手势

android - 动态改变 CardView 的背景颜色

css - 如何在窗口调整大小时更改 Bootstrap 网格?

android - BottomNavigationView 不是全宽