Android settings button color

Setting the button color requires setting the background attribute , and the value should be the selector- type xml file in res/drawable

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/mc" android:state_pressed="false"/>
    <item android:drawable="@color/purple_200" android:state_pressed="true"/>
</selector>

When setting the button color, please make sure that the app theme is not the default theme or a theme that sets button styles. It needs to be replaced with a theme that does not set button styles.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        ... ...
        
        android:theme="@style/Theme.Design.NoActionBar"
        
        ... ...>
... ...

Guess you like

Origin blog.csdn.net/m0_57150356/article/details/135375200