Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 5.x: Why does Dialog.Builder cuts text off?

I have an issue with the Dialog.Builder, where the Buttons are cut off. How can I resolve this or is this an issue for Motorola devices?

  • making the text shorter is not a solution
  • I expect the same behaviour like the S5-screenshot, Buttons too long -> Buttons below each other

Device: Motorola Moto G / OS: Android 5.0.2 enter image description here

Device: Galaxy S5 / OS: Android 5.0.2 enter image description here

Here's the code and theme for showing the Dialog

public void showDialog(final String title, final String message,                        final OnClickListener onClickPositive,                        final OnClickListener onCLickNegative, final String positiveButton,                        final String negativeButton, final boolean cancelable) {     if (!isFinishing()) {         runOnUiThread(new Runnable() {              @Override             public void run() {                  if (dialog != null && dialog.isShowing()) {                     dialog.cancel();                 }                  Builder builder;                 if (android.os.Build.VERSION.SDK_INT >= 14) {                     builder = new AlertDialog.Builder(new ContextThemeWrapper(                             MyActivity.this,                             android.R.style.Theme_DeviceDefault_Light_Dialog));                 } else {                     builder = new Builder(MyActivity.this);                 }                  if (title != null) {                     builder.setTitle(title);                 }                 if (message != null) {                     builder.setMessage(message);                 }                  if (positiveButton != null) {                     builder.setPositiveButton(positiveButton, onClickPositive);                 }                 if (negativeButton != null) {                     builder.setNegativeButton(negativeButton, onCLickNegative);                 }                 builder.setCancelable(cancelable);                  dialog = builder.show();                 colorizeDialog(dialog);             }         });     } }  //theme-xml <style name="Theme.DeviceDefault.Light.Dialog" parent="Theme.Holo.Light.Dialog" >     <item name="android:windowTitleStyle">@android:style/DialogWindowTitle.DeviceDefault.Light</item>     <item name="android:windowAnimationStyle">@android:style/Animation.DeviceDefault.Dialog</item>      <item name="android:buttonBarStyle">@android:style/DeviceDefault.Light.ButtonBar.AlertDialog</item>     <item name="borderlessButtonStyle">@android:style/Widget.DeviceDefault.Light.Button.Borderless.Small</item>      <item name="textAppearance">@android:style/TextAppearance.DeviceDefault.Light</item>     <item name="textAppearanceInverse">@android:style/TextAppearance.DeviceDefault.Light.Inverse</item> </style> 

########################

UPDATE EDIT

Seems like, the behaviour is not the same on every device. We have a second issue, with adding the "neutral" Button. Again, Galaxy S5 adding buttons below each other (from top to bottom: positiv, neutral, negative)

enter image description here

Motorola Moto G (API 5.0.2 / left side) shows neutral Button in the middle (red "Abbrechen") and cuts again the button text (blue arrow).

Nexus 4 (API 4.3 / right side) shows the neutral Button at the left side, instead of in the middle

Seems like we have to implement an custom dialog....

like image 683
longi Avatar asked Jul 20 '15 08:07

longi


People also ask

How to show AlertDialog in android Kotlin?

To set the action on alert dialog call the setPositiveButton(), setNeutralButton() and setNegativeButton() methods for positive, neutral and negative action respectively. The show() method of AlertDialog. Builder is used to display the alert dialog.

How do I get dialog on my Android?

This example demonstrate about how to make custom dialog in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

What is dialog in Android?

A dialog that can show a title, up to three buttons, a list of selectable items, or a custom layout. A dialog with a pre-defined UI that allows the user to select a date or time. Caution: Android includes another dialog class called ProgressDialog that shows a dialog with a progress bar.

Why is progressdialog deprecated in Android?

Caution: Android includes another dialog class called ProgressDialog that shows a dialog with a progress bar. This widget is deprecated because it prevents users from interacting with the app while progress is being displayed.

How to build an alertdialog in Android?

To build an AlertDialog: // 1. Instantiate an <code><a href="/reference/android/app/AlertDialog.Builder.html">AlertDialog.Builder</a></code> with its constructor // 2. Chain together various setter methods to set the dialog characteristics // 3.

How do I show a dialogfragment in Android?

When you want to show your dialog, create an instance of your DialogFragment and call show (), passing the FragmentManager and a tag name for the dialog fragment. You can get the FragmentManager by calling getSupportFragmentManager () from the FragmentActivity or getFragmentManager () from a Fragment. For example:


1 Answers

Have you tried using Dialog instead?

final Dialog dialog = new Dialog(context); dialog.setContentView(R.layout.custom); dialog.setTitle("Title...");  // set the custom dialog components - text, image and button TextView text = (TextView) dialog.findViewById(R.id.text); text.setText("Android custom dialog example!");  // make 3 buttons instead of one Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK); // if button is clicked, close the custom dialog dialogButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) {     //do something     } });  dialog.show(); 

recommendation: use linear layout for the dialog.

like image 52
Francisco Avatar answered Sep 28 '22 01:09

Francisco