如何解决在黑暗模式下更改材质按钮主题
请帮帮我。
同时将主题从浅色模式更改为深色模式。如何将按钮的主题从填充按钮更改为轮廓按钮?
我在 Play 商店看到了一个应用。在这里,我注意到按钮主题正在发生变化:
这是灯光模式:
这是黑暗模式:
我想像这样更改按钮主题。谁能告诉我怎么做?
任何帮助将不胜感激
谢谢。
解决方法
使用“androidx.appcompat.widget.AppCompatButton”而不是“Button”它会随着UI主题自动改变。 Please check Image here for better Understanding
,在您的主题中使用 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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。