我試圖在有人單擊某個按鈕時更改按鈕的樣式。我想將背景改爲文字顏色。但是,只有文本顏色發生了變化。從這我得出結論的樣式是已更改,但由於某些原因背景不能被覆蓋。更改樣式只能部分工作:文本顏色更改,背景不更改
我使用這個代碼在onclick處理程序:
Button send_button = (Button) findViewById(R.id.button1);
send_button.setTextAppearance(context, R.style.activeButtonTheme);
我styles.xml相關風格:
<style name="buttonTheme">
<item name="android:background">@color/white</item>
<item name="android:textColor">@color/orange</item>
<item name="android:paddingTop">6dp</item>
<item name="android:paddingBottom">6dp</item>
<item name="android:layout_margin">2dp</item>
</style>
<style name="activeButtonTheme" parent="@style/buttonTheme">
<item name="android:background">@color/orange</item>
<item name="android:textColor">@color/white</item>
</style>
這裏有什麼問題嗎?
我不想從Java設置背景顏色,我只想改變Java中的樣式。
確保您的java代碼中不存在對'setBackground'的調用。 – 2013-05-09 09:18:32
@AdamArold除了這個和alertDialog之外沒有任何東西。 – Keelan 2013-05-09 09:19:15