0

Please Help Me.

While changing the theme from light mode to dark mode. How do I change the button's theme from filledbutton to outlinedbutton?

I saw an app from play store. Here I noticed that the buttons theme is changing:

This is LIGHT MODE :

enter image description here

This is DARK MODE :

enter image description here

I want to change the buttons theme like this. Can anybody tell how to do that?

Any help would be appreciated

Thank you.

2 Answers2

1

Use the materialButtonStyle attribute in your theme:

<style name="AppTheme" parent="Theme.MaterialComponents.*">
   ...
   <item name="materialButtonStyle">@style/CustomButton</item>
</style>

Then in a light theme use Widget.MaterialComponents.Button as parent:

<style name="CustomButton" parent="@style/Widget.MaterialComponents.Button">
  ...
</style>

and in the values-night directory use the Widget.MaterialComponents.Button.OutlinedButton as parent:

<style name="CustomButton" parent="Widget.MaterialComponents.Button.OutlinedButton">
   ...
</style>
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
0

use " androidx.appcompat.widget.AppCompatButton "this instead of " Button" this it will automatically changes with the UI theme. Please check Image here for better Understanding