我尝试仅使用 Material Components 中的小部件,但在许多情况下,没有记录如何实现样式。
让我们考虑一下MaterialAlertDialog
.
每次我想显示一个对话框时,我都会调用这部分代码:
MaterialAlertDialogBuilder(context, R.style.Theme_MyApp_Dialog_Alert)
.setTitle("Title")
.setMessage("This is message.")
.setPositiveButton(R.string.ok) { _, _ -> }
.show()
如您所见,我正在使用自定义主题。
<style name="Theme.MyApp.Dialog.Alert" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<!-- attributes here -->
</style>
问题是某些属性不起作用。例如textColor
。所以问题是如何更改正文或标题文本颜色MaterialAlertDialog
?
我使用最新版本的 Material Components -1.1.0-alpha07
.
PS.
我不确定哪个主题应该是父母的。在材质主题生成器 https://github.com/material-components/material-components-android/tree/master/material-theme-builder他们使用@style/ThemeOverlay.MaterialComponents.Dialog.Alert
这实际上给出了对话框的“旧”外观。
更改样式如下
<style name="Theme.MyApp.Dialog.Alert" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="materialAlertDialogTitleTextStyle">@style/MaterialAlertDialogText</item>
</style>
Create MaterialAlertDialogText
样式并设置文本颜色
<style name="MaterialAlertDialogText" parent="@style/MaterialAlertDialog.MaterialComponents.Title.Text">
<item name="android:textColor">@color/yourTextColor</item>
</style>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)