Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use MaterialAlertDialogBuilder fine?

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'

Im use this theme

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

MaterialComponent code

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

Screenshot_20190512-115103_2

AlertDialog.Builder

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

Screenshot_20190512-115241_2

Where is the problem?

like image 911
Rulogarcillan Avatar asked May 12 '19 10:05

Rulogarcillan


People also ask

How can I make alert dialog fill 100% of screen size?

If your dialog is made out of a vertical LinearLayout, just add a "height filling" dummy view, that will occupy the entire height of the screen. Nice!

How do I dismiss Materialalertdialogbuilder?

setCancelable(false); AlertDialog dialog = builder. show(); In order to dismiss the dialog, you can call dismiss function like this. Save this answer.

How do I create an alert dialog in Kotlin?

Create an AlertDialog Builder using the activity's context. Set message content using the builder. Set Positive Button Text and Action to be taken when the button is clicked using the builder. Set Negative Button Text and Action to be taken when the button is clicked using the builder.


3 Answers

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>

and then:

 new MaterialAlertDialogBuilder(this,
      R.style.Body_ThemeOverlay_MaterialComponents_MaterialAlertDialog)
            .setTitle("Title")
            .setMessage("Message......")
            ...
            .show();

enter image description hereenter image description here

like image 111
Gabriele Mariotti Avatar answered Nov 13 '22 17:11

Gabriele Mariotti


You can solve like this:

<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>
like image 27
郑少鹏 Avatar answered Nov 13 '22 15:11

郑少鹏


You need to use MaterialAlertDialogBuilder instead of AlertDialog.Builder.

MaterialAlertDialogBuilder(this)
            .setMessage("This is a test of AlertDialog.Builder")
            .setPositiveButton("Ok", null)
            .show()
like image 24
chrisonline Avatar answered Nov 13 '22 16:11

chrisonline