更改字体大小到AlertDialog [英] Changing font size into an AlertDialog

查看:613
本文介绍了更改字体大小到AlertDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图把一些loooong文本到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.

解决方法1)使用一个TextView和myView.setTextSize(12);

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();

问题的:布局不滚动

解决方法2)制作的TextView滚动。

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.)

解决方法3)使用滚动型。

这就是我要试试,但我不能相信,有没有更简单的解决方案...

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

推荐答案

实际上,你可以访问该消息的TextView的pretty的轻松,然后改变它的大小。我用大一号的测试,但你可以使用任何你想要的大小。该文本将滚动很好,因为它已经这样做了。该视图的id是android.R.id.message:

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);

这可能是一个更清洁的解决方案,但我不知道是否有一个风险,即TextView的可能是空或不是。

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

这篇关于更改字体大小到AlertDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆