减少AlertDialog.Builder的部件的字体大小 [英] Reducing font size of AlertDialog.Builder's components

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

问题描述

我创建了一个 AlertDialogue 使用以下code:

I created an AlertDialogue using the following code :

 int selectedModeId=0;
 public void sortTypeModeSelection(){

    AlertDialog.Builder alertBuilder=new AlertDialog.Builder(WatchListDetailActivity.this);

    alertBuilder.setSingleChoiceItems(R.array.watchlist_sorting_modes,selectedModeId, new DialogInterface.OnClickListener(){
        public void onClick(DialogInterface dialog, int which) {
            switch (which){
                case 0:
                    selectedModeId=0;
                    break;
                case 1:
                    selectedModeId=1;
                    break;
                case 2:
                    selectedModeId=2;
                    break;
                case 3:
                    selectedModeId=3;
                    break;
                case 4:
                    selectedModeId=4;
                    break;
                case 5:
                    selectedModeId=5;
                    break;
                case 6:
                    selectedModeId=6;
                    break;
                case 7:
                    selectedModeId=7;
                    break;
            }
            dialog.cancel();
        }
    });
    alertBuilder.show();
}

我发警报,但我想,以减少该对话框的列表项的字体大小。我怎样才能做到这一点?

I made the alert, but I want to reduce the font size of the list items of the dialog. How can I do this?

注意:不推荐膨胀的自定义布局做到这一点,我想知道是否有另一种方法

Note: Don't recommend inflating a custom layout to accomplish this, I wish to know if there is another approach.

推荐答案

我可以通过样式来实现这一目标。我说这种风格对我 styles.xml 文件中的值目录:

I was able to achieve this through styles. I added this style to my styles.xml file in the values directory:

<style name="AlertDialogTheme" parent="android:Theme.Dialog">
    <item name="android:textSize">14sp</item>
</style>

然后在创建 AlertDialog ,我包的活动范围内的 ContextThemeWrapper ,并通过了进入生成器构造器:

Then when creating the AlertDialog, I wrapped the activity context in a ContextThemeWrapper and passed that into the Builder constructor:

ContextThemeWrapper cw = new ContextThemeWrapper( this, R.style.AlertDialogTheme );
AlertDialog.Builder b = new AlertDialog.Builder( cw );

这产生较小的文本大小的对话框列表中的项目。

This produced smaller text size for the list items in the dialog.

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

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