0

I have two styles for my button:

<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>

I know i can set a theme in my layout xml like this:
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:theme="@style/PrimaryButton1"/>

but i want to change the theme between these two styles when a click event occur.
(the reason i am using themes is changing the background of my button makes it's reveal effect delete)
how can i do this?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
hamid
  • 17
  • 1

1 Answers1

0
  1. Add an id for the Button Or Add the android:onClick="{method name}" to the Button XML
  2. Add this code into your Activity / Fragment
    (Assuming you've defined a variable for the Button named button)

    Inside an

    Activity: button.setTextAppearance(getApplicationContext(), R.style.PrimaryButton2);
    Fragment:button.setTextAppearance(getContext(), R.style.PrimaryButton2);