如何使用MaterialAlertDialogBu​​ilder罚款? [英] How to use MaterialAlertDialogBuilder fine?

查看:120
本文介绍了如何使用MaterialAlertDialogBu​​ilder罚款?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用dialog.builder时,字体大小正确,但是当我使用MaterialAlertDialogBu​​ilder时,正文文本的字体大小较小.可以吗?

When i use dialog.builder the font size is correct but when i use MaterialAlertDialogBuilder the font size of body text is smaller. its ok?

implementation 'com.google.android.material:material:1.1.0-alpha06'

我使用此主题

<style name="AppTheme" parent="Theme.MaterialComponents.Light">

MaterialComponent代码

MaterialComponent code

MaterialAlertDialogBuilder(this)
    .setMessage("This is a test of MaterialAlertDialogBuilder")
    .setPositiveButton("Ok", null)
    .show()

AlertDialog.Builder

AlertDialog.Builder

AlertDialog.Builder(this)
            .setMessage("This is a test of AlertDialog.Builder")
            .setPositiveButton("Ok", null)
            .show()

问题出在哪里?

推荐答案

这是故意的.他们使用不同的样式.

It is intentional. They are using different styles.

您可以使用以下方式更改它:

You can change it using something like:

  <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();

这篇关于如何使用MaterialAlertDialogBu​​ilder罚款?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆