[英]Android - How to change the color of all button when it being clicked
What I would like to know is, if there's a way to change any click color at the whole Activity. 我想知道的是,是否有办法在整个活动中更改任何点击颜色。
I've set up a the maniest the next Activity - 我已经设置了最丰富的下一个活动-
<activity android:name="com.example.test.MainActivity"
android:theme="@style/Theme.Base.AppCompat.Light.DarkActionBar"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" >
</action>
<category android:name="android.intent.category.NORMAL" >
</category>
</intent-filter>
</activity>
As you can see I am using the next theme for the Activity - 如您所见,我正在为活动使用下一个主题-
android:theme="@style/Theme.Base.AppCompat.Light.DarkActionBar"
This make any click color to be blue- meaning when a button or anything else is being pressed it turning into blue when it's clicked. 这会使任何点击颜色变为蓝色,这意味着当按下按钮或其他任何按钮时,它会变成蓝色。
Now what i would like to know is there any way to change the blue color into a diffrent color, and now by changing the background for each view item that i'm gonna use. 现在我想知道有什么方法可以将蓝色更改为另一种颜色,现在可以通过更改我要使用的每个视图项目的背景。
Thanks for any kind of help 谢谢你的帮助
file name: /res/drawable/button_color.xml 文件名:/res/drawable/button_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@color/color1"/>
<item android:state_focused="true" android:drawable="@color/color1"/>
<item android:state_pressed="true" android:drawable="@color/color1"/>
<item android:drawable="@color/color1"/>
Take this file into your Button Style like this: 将此文件放入您的Button样式中,如下所示:
create new style in your resource value folder like below example and change your application attribute android:theme="@style/CustomActionBarTheme"
在资源值文件夹中创建新样式,如下例,并更改应用程序属性
android:theme="@style/CustomActionBarTheme"
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="@style/Theme.Base.AppCompat.Light.DarkActionBar>
<item name="android:buttonStyle">@style/srp_button</item>
</style>
<style name="srp_button" parent="@android:style/Widget.Button">
<itemname="android:background">@drawable/button_color</item> <!-- Here isspecifiedtext color -->
</style>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.