BollMose
BollMose

Reputation: 3498

Button under an AppCompatActivity isn't change to AppCompatButton automatically on runtime?

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

Upvotes: 1

Views: 307

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364556

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.

Upvotes: 1

Related Questions