Android: AlertDialog message does not wrap automatically on SDK <11

I am having a problem with AlertDialog

which I created programmatically: its message is displayed correctly in my emulator running on 4.1.2. But on my device (Huawei U8510 running 2.3.7) the message doesn't wrap automatically.

Is there anything I can add to the code for the AlertDialog to resolve its message? I obviously don't want to add manual line breaks. (The thing is, even when I add manual line breaks, the dialog only shows the first line)

I'm guessing something is missing here, but I couldn't find the answer anywhere - they all relate to manually adding line breaks.

Here is the relevant code (yes, I'm currently using hardcoded bites):

AlertDialog.Builder builder= new AlertDialog.Builder( activity );
builder.setPositiveButton( ...
builder.setNegativeButton( ...
builder.setTitle( "Wirklich löschen?" );
builder.setMessage( "Soll das Item \"" + deleteItem + "\" wirklich gelöscht werden?" );
AlertDialog dialog= builder.create();
dialog.show();

      

And here are the screenshots. You can see how the message is wrapped correctly on the emulator (large image), but not on the device.

Device (2.3.7)

Emulator (4.1.2)

+3


source share


3 answers


I'm not sure what the problem is, or if it is device specific, or what, but I can suggest a job for this situation. You can create your own layout with a text image and two buttons at the bottom and attach this layout to this dialog. Now you can handle the text representation however you want ...



+3


source


I recently ran into this problem on a project that was migrated from Android Studio back to Eclipse.

In this situation, the problem was minSdkVersion was not defined. If you do not declare this attribute, the system defaults to "1", which means that your application is compatible with all versions of Android.

Obviously API Level 1 (which is even earlier than Cupcake 1.5) did not wrap the AlertDialog message text.

The problem was solved by adding



<uses-sdk android:minSdkVersion="16" />

      

to the android manifest. This app requires minSdkVersion 16 (Jelly Bean). I don't know when the AlertDialog started wrapping the message text, but earlier API levels for example. 10 (Gingerbread) might work as well.

On a separate note, others have found that using Theme.Holo on earlier versions of Android can cause this problem, for example. Android TextView has stopped wrapping text

+1


source


If you want a consistent look and feel across all Android versions, you should consider using a custom layout.

In this case, the simple one TextView

should do the job. You can style, align, and change the appearance of the text to suit your needs.

custom_dialog.xml

<TextView
    android:id="@+id/custom_dialog_message"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/white"
    android:textSize="20sp" />

      

Then use the following method to apply it to your dialog:

dialog.setContentView(R.layout.custom_dialog);

      

0


source







All Articles