2016-08-13 24 views
-2

我正在製作Android應用程序,但無法更改項目中所有按鈕的默認背景色。Android中整個項目中更改按鈕背景色

我能做到的唯一方法就是逐個改變它們。

有沒有其他辦法?

+0

有多少有按鈕? 只需複製粘貼您的xml文本即可獲得相同的背景色按鈕 –

回答

0

在你的主題中設置buttonStyle。

類似以下內容: (我假設你使用AppCompat

在你style.xml:

<resources> 

    <style name="AppTheme" parent="Theme.AppCompat"> 
     ... 
     <item name="buttonStyle">@style/YourButtonStyle</item> 
     <!-- For preview --> 
     <item name="android:buttonStyle">@style/YourButtonStyle</item> 
    </style> 

    <style name="YourButtonStyle" parent="@style/Widget.AppCompat.Button"> 
     <!-- Set background --> 
     <item name="android:background">@drawable/your_button_drawable</item> 
    </style> 

</resources> 

在AndroidManifest.xml中:

<application 
    ... 
    android:theme="@style/AppTheme" > 
+0

我必須對按鈕的xml進行任何更改嗎? – Cipirinha

+0

是的,不應該改變按鈕的。 – nshmura

+0

謝謝,現在正在爲我工​​作 – Cipirinha