解決Android Studio Button無法改變背景顏色

新版Android Studio下button背景全為亮紫色,不能修改。

解決方法:

方法一:

res/values/themes下的所有themes.xml

<style name=”…”> 後面的

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
parent="Theme.MaterialComponents.DayNight.DarkActionBar"
parent="Theme.MaterialComponents.DayNight.DarkActionBar"
parent="Theme.MaterialComponents.DayNight.DarkActionBar"

改成

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge"
parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge"
parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge"

可能需要重啟Android studio

方法二:

因為顏色被backgroundTint覆蓋了,加入

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
app:backgroundTint="@null"
app:backgroundTint="@null"
app:backgroundTint="@null"

背景顏色即可顯示

方法三:

AndroidMainifest.xml中的android:theme改成

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
android:theme="@style/Theme.AppCompat"
android:theme="@style/Theme.AppCompat"
android:theme="@style/Theme.AppCompat"

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
android:theme="@style/Theme.AppCompat.NoActionBar"
android:theme="@style/Theme.AppCompat.NoActionBar"
android:theme="@style/Theme.AppCompat.NoActionBar"