简体   繁体   English

Android-单击时如何更改所有按钮的颜色

[英]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.

相关问题 在android中单击时如何更改按钮颜色 - how to change button color when it is clicked in android 单击时如何更改 Android 中按钮的颜色? - How to Change color of Button in Android when Clicked? Android:点击时更改按钮颜色 - Android: Change button color when clicked 单击时更改按钮颜色 Android Studio - Change Button Color When Clicked Android Studio 在 Android Studio 中按住按钮时如何更改按钮的背景颜色? - How to change the background color of a button when being held in Android Studio? 在Android中单击按钮时如何更改ListView的按钮背景颜色 - How to change listview's button background color when button clicked in android 单击无边界按钮时如何为背景设置特定颜色? - How to set specific color for background when being clicked on borderless button? 在android中单击按钮时更改textview文本颜色 - Change the textview text color when button is clicked in android 在 Android Studio 中按住按钮本身时,如何更改按钮图标的颜色? - How to change the color of a button's icon when the button itself is being held in Android Studio? 单击时如何更改按钮的颜色和暂停屏幕几秒钟? - How to change the color of button and pause screen for few second when it clicked?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM