0

I'm using this trick to change the background color of all the application buttons:

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="colorButtonNormal">@color/unpressed2</item>
</style>

It's working perfectly in post-Lollipop (api 21) devices but in pre-Lollipop it's being ignored.

How can I change the background color of the buttons also in pre-Lollipop devices?

halfer
  • 19,824
  • 17
  • 99
  • 186
NullPointerException
  • 36,107
  • 79
  • 222
  • 382
  • How you're applying it? – Rahul Khurana Sep 25 '19 at 09:43
  • try giving `android:colorButtonNormal` also – Rahul Khurana Sep 25 '19 at 09:44
  • @RahulKhurana I'm applying it simply with the code I attached in the question. And android:colorButtonNormal does not exist below api 21, android: must be used only if you are above api 21. – NullPointerException Sep 25 '19 at 09:48
  • You might want to check this: https://stackoverflow.com/questions/26519979/coloring-buttons-in-android-with-material-design-and-appcompat#comment47930599_29053700 – Rahul Khurana Sep 25 '19 at 09:56
  • Do these devices still exist? – Gabriele Mariotti Sep 25 '19 at 09:57
  • @RahulKhurana tryed all the solutions in that post and also the solution of that comment you linked me. None of them worked. – NullPointerException Sep 25 '19 at 10:09
  • @NullPointerException Have you tried applying it to individual View as explained here: https://stackoverflow.com/a/37127051/4079010 – Rahul Khurana Sep 25 '19 at 10:13
  • @RahulKhurana yes, I tryed. It seems that adding implementation 'com.android.support:appcompat-v7:28.0.0' is not transforming all my Buttons in android.support.v7.widget.AppCompatButton. Why? If i forze to be android.support.v7.widget.AppCompatButton instead of Button some solutions works. But it's very rare, because It's supposed that just adding that line in grafle file will transform all the buttons in appcompatbuttons but it's not happening. why? – NullPointerException Sep 25 '19 at 10:18
  • @NullPointerException As mentioned in the last link are you using `android:theme` with android.support.v7.widget.AppCompatButton? – Rahul Khurana Sep 25 '19 at 10:21
  • @RahulKhurana yes, tryed it, the solutions only works if I forze to use android.support.v7.widget.AppCompatButton instead of just Button. Please, can you answer my question from the previous comment? I think that understanding that is the key for solve this problem – NullPointerException Sep 25 '19 at 10:25
  • @NullPointerException If you want to use it with button see here: https://stackoverflow.com/questions/26519979/coloring-buttons-in-android-with-material-design-and-appcompat#comment52579555_32238489 – Rahul Khurana Sep 25 '19 at 10:33
  • @NullPointerException about why it is not working because it is not supported: https://stackoverflow.com/questions/26519979/coloring-buttons-in-android-with-material-design-and-appcompat#comment44433226_27505229 – Rahul Khurana Sep 25 '19 at 10:35
  • thank you very much, @RahulKhurana it worked changing the activity to AppCompatActivity. Please can you post an answer? if not, I will post the answer, but other persons can find this problem too – NullPointerException Sep 25 '19 at 12:46
  • @NullPointerException posted it as answer. – Rahul Khurana Sep 25 '19 at 13:40

1 Answers1

1

If you want your Button to work with colorButtonNormal your activity needs to extend AppCompatActivity

Rahul Khurana
  • 8,577
  • 7
  • 33
  • 60