Search code examples
androidbuttontextcolor

Text color of selected button android


I have a button like so:

<Button
        android:id="@+id/button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:text="Button"
        android:textColor="@color/my_gray" />

After pressing the button, the text color turns a darker gray color (a "this has already been pressed" color). How do I prevent this? On the button press I do button.setTextColor(R.color.my_gray); to reset the color, but it has no effect.


Solution

  • Try using a different kind of button. CompoundButton or ImageButton might work out for you since you can control their backgrounds/images more easily.

    However, the best way to do it might be to use a selector like this guide shows.