1

It's said Button will be transferred to AppCompatButton under AppCompatActivity, but I just found that's not happening for me. The same issue as here Android Button background color not changing.

I checked this here https://developer.android.com/reference/androidx/appcompat/widget/AppCompatButton

This will automatically be used when you use Button in your layouts and the top-level activity / dialog is provided by appcompat. You should only need to manually use this class when writing custom views.

What does mean "You should only need to manually use this class when writing custom views."?

Updated:

  1. First of all, you should know which theme you are basing on, "Theme.MaterialComponents.DayNight.DarkActionBar" or "Theme.AppCompat.Light.NoActionBar", check the theme or style file
  2. for AS4.1, wizard created project will use material design
  3. For filled buttons, this class uses your theme's ?attr/colorPrimary for the background tint color and ?attr/colorOnPrimary for the text color. For unfilled buttons, this class uses ?attr/colorPrimary for the text color and transparent for the background tint.
  4. Please read more here https://developer.android.com/reference/com/google/android/material/button/MaterialButton
  5. Remember, not only Button, but also all widgets, material design uses a total different way
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
BollMose
  • 3,002
  • 4
  • 32
  • 41
  • 1
    See https://stackoverflow.com/a/64839917/115145 and https://commonsware.com/blog/2020/11/14/poor-default-why-button-does-not-work.html for what I think your root problem is. "What does mean..." -- if you want to create a custom view that otherwise behaves like an `AppCompatButton`, you would need to create a subclass of `AppCompatButton`. Usually, you do not need `` elements in a layout resource. If you use a ` – CommonsWare Feb 07 '21 at 14:31
  • Thanks. @CommonsWare But I just want to say, so much legacy for Android isn't a good idea. – BollMose Feb 08 '21 at 01:41
  • This is one of the reasons why Google is investing a lot of staff time in Jetpack Compose, to try to put some of the legacy views behind it. – CommonsWare Feb 08 '21 at 12:03

1 Answers1

1

Button will be transferred to AppCompatButton under AppCompatActivity

It is not correct.
It depends by the theme used in your Activity.

The MaterialComponentsViewInflater replaces some framework widgets with Material Components ones at inflation time, provided if a MaterialComponents.* theme is in use.

Something similar happens also with AppCompat theme with the AppCompatViewInflater. You can check that MaterialComponentsViewInflater extends AppCompatViewInflater.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841