【发布时间】:2013-05-09 09:04:07
【问题描述】:
当有人点击按钮时,我正在尝试更改按钮的样式。我想将背景都更改为文本颜色。但是,仅更改了文本颜色。由此我得出结论,样式 已更改,但由于某种原因,无法覆盖背景。
我在 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的调用。 -
@AdamArold 除了这个和alertDialog之外什么都没有。
标签: java android styles android-styles