首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用MaterialAlertDialogBuilder fine?

如何使用MaterialAlertDialogBuilder fine?
EN

Stack Overflow用户
提问于 2019-05-12 18:09:01
回答 3查看 11.1K关注 0票数 8

当我使用dialog.builder时,字体大小是正确的,但当我使用MaterialAlertDialogBuilder时,正文文本的字体较小。还好吗?

代码语言:javascript
复制
implementation 'com.google.android.material:material:1.1.0-alpha06'

我正在使用这个主题

代码语言:javascript
复制
<style name="AppTheme" parent="Theme.MaterialComponents.Light">

MaterialComponent代码

代码语言:javascript
复制
MaterialAlertDialogBuilder(this)
    .setMessage("This is a test of MaterialAlertDialogBuilder")
    .setPositiveButton("Ok", null)
    .show()

AlertDialog.Builder

代码语言:javascript
复制
AlertDialog.Builder(this)
            .setMessage("This is a test of AlertDialog.Builder")
            .setPositiveButton("Ok", null)
            .show()

问题出在哪里?

EN

回答 3

Stack Overflow用户

发布于 2019-09-26 06:01:33

这是故意的。他们使用不同的风格。

您可以使用类似以下内容来更改它:

代码语言:javascript
复制
  <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>

然后:

代码语言:javascript
复制
 new MaterialAlertDialogBuilder(this,
      R.style.Body_ThemeOverlay_MaterialComponents_MaterialAlertDialog)
            .setTitle("Title")
            .setMessage("Message......")
            ...
            .show();

票数 8
EN

Stack Overflow用户

发布于 2019-05-17 10:00:51

你可以像这样解决:

代码语言:javascript
复制
<item name="materialAlertDialogTheme">@style/ThemeOverlay.MyApp.Dialog</item>

<style name="ThemeOverlay.MyApp.Dialog" parent="@style/ThemeOverlay.MaterialComponents.Dialog">
    <item name="android:dialogCornerRadius" tools:targetApi="p">@dimen/dp_4</item>
    <item name="android:paddingBottom">@dimen/dp_2</item>
    ...
</style>
票数 2
EN

Stack Overflow用户

发布于 2019-07-18 02:29:13

您需要使用MaterialAlertDialogBuilder而不是AlertDialog.Builder

代码语言:javascript
复制
MaterialAlertDialogBuilder(this)
            .setMessage("This is a test of AlertDialog.Builder")
            .setPositiveButton("Ok", null)
            .show()
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56098162

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档