我的按钮有两种样式:
<style name="PrimaryButton1" parent="Theme.AppCompat">
<item name="colorButtonNormal">@color/white</item>
<item name="colorControlHighlight">@color/blackt</item>
</style>
<style name="PrimaryButton2" parent="Theme.AppCompat">
<item name="colorButtonNormal">@color/black</item>
<item name="colorControlHighlight">@color/white</item>
</style>
我知道我可以这样在我的布局xml中设置一个主题:
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:theme="@style/PrimaryButton1"/>
但是当点击事件发生时,我想在这两种风格之间切换主题。
我该怎么做呢?
发布于 2018-07-02 01:19:12
android:onClick="{method name}"
添加到按钮XML(假设您已经为名为Button的button定义了一个变量)
练习:button.setTextAppearance(getApplicationContext(), R.style.PrimaryButton2);
Fragment:button.setTextAppearance(getContext(), R.style.PrimaryButton2);
https://stackoverflow.com/questions/51125311
复制相似问题