Android studio 在暗模式下更改材质按钮主题

Android studio 在暗模式下更改材质按钮主题,android-studio,android-layout,android-button,android-dark-theme,android-studio-4.2,Android Studio,Android Layout,Android Button,Android Dark Theme,Android Studio 4.2,请帮帮我 将主题从浅模式更改为暗模式时。如何将按钮的主题从filledbutton更改为outlinedbutton 我在play store中看到一个应用程序。在这里,我注意到按钮主题正在发生变化: 这是灯光模式: 这是黑暗模式: 我想像这样更改按钮主题。谁能告诉我怎么做 任何帮助都将不胜感激 谢谢。使用“androidx.appcompat.widget.AppCompatButton”代替“Button”,它将随UI主题自动更改。 在主题中使用materialButtonStyle属性

请帮帮我

将主题从浅模式更改为暗模式时。如何将按钮的主题从filledbutton更改为outlinedbutton

我在play store中看到一个应用程序。在这里,我注意到按钮主题正在发生变化:

这是灯光模式:

这是黑暗模式:

我想像这样更改按钮主题。谁能告诉我怎么做

任何帮助都将不胜感激

谢谢。

使用“androidx.appcompat.widget.AppCompatButton”代替“Button”,它将随UI主题自动更改。
在主题中使用
materialButtonStyle
属性:

<style name="AppTheme" parent="Theme.MaterialComponents.*">
   ...
   <item name="materialButtonStyle">@style/CustomButton</item>
</style>
values-night
目录中,使用
Widget.MaterialComponents.Button.OutlinedButton
作为父项:

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

...