Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing font size into an AlertDialog

I am trying to put some loooong text into an AlertDialog. The only issue the default font size that is really too big, so I want to make it smaller.

Here are all the workaround I tried and their issues.

Workaround 1) Using a TextView and myView.setTextSize(12);

final TextView myView = new TextView(getApplicationContext()); myView.setText(myLongText); myView.setTextSize(12); final AlertDialog d = new AlertDialog.Builder(context)     .setPositiveButton(android.R.string.ok, null) .setTitle(myTitle) .setView(myView) .create(); 

Issues: Layout is not scrolling

Workaround 2) making TextView scrollable.

message.setMovementMethod(LinkMovementMethod.getInstance()); 

Issues: Layout is scrolling, bute there is no "inertia" (don't know how to call that.. But I guess you understand.)

Workaround 3) Using a Scrollview.

That's what I am going to try, but I cannot believe there are no easier solutions...

like image 732
Waza_Be Avatar asked Jul 03 '11 12:07

Waza_Be


People also ask

How do I change the font in AlertDialog?

If you only want to change text format, you can just override alertDialogTheme attribute to change the theme for the AlertDialog . <style name="MyTheme" parent="Theme. AppCompat.

How do I change the AlertDialog text size in Android?

AlertDialog dialog = new AlertDialog. Builder(this). setMessage("Hello world"). show(); TextView textView = (TextView) dialog.

How do I set the width and height of an AlertDialog?

show(); alertDialog. getWindow(). setLayout(600, 400); //Controlling width and height. Or you can do it in my way.

Is AlertDialog deprecated?

A simple dialog containing an DatePicker . This class was deprecated in API level 26.


1 Answers

You can actually get access to the message's TextView pretty easily, and then change it's size. I tested with a bigger size, but you could use whatever size you want. The text will scroll nicely as it already does. The view's id is android.R.id.message

    AlertDialog dialog = new AlertDialog.Builder(this).setMessage("Hello world").show();     TextView textView = (TextView) dialog.findViewById(android.R.id.message);     textView.setTextSize(40); 

This is probably a cleaner solution, though I'm not sure if there's a risk that the TextView could be null or not.

like image 198
Gregory Avatar answered Sep 28 '22 01:09

Gregory