0

请帮我。

同时将主题从浅色模式更改为深色模式。如何将按钮的主题从填充按钮更改为轮廓按​​钮?

我从Play商店看到了一个应用程序。在这里,我注意到按钮主题正在发生变化:

这是灯光模式:

在此处输入图像描述

这是黑暗模式:

在此处输入图像描述

我想像这样更改按钮主题。任何人都可以告诉如何做到这一点?

任何帮助,将不胜感激

谢谢你。

4

2 回答 2

0

使用“androidx.appcompat.widget.AppCompatButton”而不是“Button”,它会随着 UI 主题自动改变。 请在此处查看图片以获得更好的理解

于 2021-06-03T05:20:28.443 回答
0

在您的主题中使用该materialButtonStyle属性:

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

然后在轻主题Widget.MaterialComponents.Button中用作父级:

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

并在values-night目录中使用Widget.MaterialComponents.Button.OutlinedButton作为父级:

<style name="CustomButton" parent="Widget.MaterialComponents.Button.OutlinedButton">
   ...
</style>
于 2021-06-15T08:42:13.263 回答