请帮我。
同时将主题从浅色模式更改为深色模式。如何将按钮的主题从填充按钮更改为轮廓按钮?
我从Play商店看到了一个应用程序。在这里,我注意到按钮主题正在发生变化:
这是灯光模式:
这是黑暗模式:
我想像这样更改按钮主题。任何人都可以告诉如何做到这一点?
任何帮助,将不胜感激
谢谢你。
请帮我。
同时将主题从浅色模式更改为深色模式。如何将按钮的主题从填充按钮更改为轮廓按钮?
我从Play商店看到了一个应用程序。在这里,我注意到按钮主题正在发生变化:
这是灯光模式:
这是黑暗模式:
我想像这样更改按钮主题。任何人都可以告诉如何做到这一点?
任何帮助,将不胜感激
谢谢你。
使用“androidx.appcompat.widget.AppCompatButton”而不是“Button”,它会随着 UI 主题自动改变。 请在此处查看图片以获得更好的理解
在您的主题中使用该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>