android - 如何很好地使用 MaterialAlertDialogBuilder?
问题描述
当我使用 dialog.builder 时,字体大小是正确的,但是当我使用 MaterialAlertDialogBuilder 时,正文的字体大小更小。没关系?
implementation 'com.google.android.material:material:1.1.0-alpha06'
我用这个主题
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
材质组件代码
MaterialAlertDialogBuilder(this)
.setMessage("This is a test of MaterialAlertDialogBuilder")
.setPositiveButton("Ok", null)
.show()
警报对话框生成器
AlertDialog.Builder(this)
.setMessage("This is a test of AlertDialog.Builder")
.setPositiveButton("Ok", null)
.show()
问题出在哪里?
解决方案
这是故意的。他们使用不同的风格。
您可以使用以下方式更改它:
<style name="Body_ThemeOverlay.MaterialComponents.MaterialAlertDialog" parent="@style/ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="materialAlertDialogBodyTextStyle">@style/BodyMaterialAlertDialog.MaterialComponents.Body.Text</item>
</style>
<style name="BodyMaterialAlertDialog.MaterialComponents.Body.Text" parent="MaterialAlertDialog.MaterialComponents.Body.Text">
<item name="android:textColor">@color/colorAccent</item>
<item name="android:textAllCaps">true</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">bold</item>
</style>
接着:
new MaterialAlertDialogBuilder(this,
R.style.Body_ThemeOverlay_MaterialComponents_MaterialAlertDialog)
.setTitle("Title")
.setMessage("Message......")
...
.show();
推荐阅读
- reactjs - 使用 Axios (React) 和 Django RestFramework 的奇怪行为 - 第一次尝试网络错误第二次尝试成功
- javascript - 为什么从字段中删除所有文本时会删除 p(段落)标签?
- botframework - 如何使用 Bot Framework composer 重命名机器人
- c++ - 如何在 MacOS 上获取文件类型的图标?
- python - 验证基于另一个数据帧的数据帧?
- gerrit - Gerrit 总是更新父级未合并提交补丁集
- ms-access-2010 - 是否可以重新查询使用 Docmd.openform "nameform",,,,acformAdd 打开的表单?
- javascript - 对象在下一个 js 中作为 React 子错误无效
- python - 调用后Python设置类变量
- javascript - PDF下载按钮