AlerDialog可以加载xml,自定义一个AlerDialog就行了,,,

解决方案 »

  1.   

    在继承的ListPreference中,没有找到构造AlertDialog的时机,强行构造(就像我下面试了的两种方法),得不到正确的结果
      

  2.   

    额,bulider.setView(view)啊,因为只有通过view才能设置字体大小,,,
      

  3.   

    这个view怎么写呢,还是不太明白,我之前也用过这个方法,不过view里面都是写的自己添加的控件,而现在是要改builder的内置的item的字体,怎么在view里面写?
      

  4.   

    网络上有很多例子,你可以百度下,或者看下api,我一般是写个dialog.xml,然后bulider.setContentView(R.layout.dialog); 这样就可以自定义样式了,,,
      

  5.   

    http://blog.csdn.net/yunyu5120/article/details/10890921这篇帖子挺不错的,,,
      

  6.   

    LS啊,我还是不怎么明白,我写了个简单的demo在这里
    http://good.gd/2931466.htm
    点立即下载即可就是要改变类别里面的“正常人”“脑残”“非主流”这几个字的大小,麻烦你看看好么
      

  7.   

    帮你看了,@Override
        protected void onPrepareDialogBuilder(Builder builder) {
            super.onPrepareDialogBuilder(builder);
            
            if (mEntries == null || mEntryValues == null) {
                throw new IllegalStateException(
                        "ListPreference requires an entries array and an entryValues array.");
            }        mClickedDialogEntryIndex = getValueIndex();
            builder.setSingleChoiceItems(mEntries, mClickedDialogEntryIndex, 
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            mClickedDialogEntryIndex = which;                        /*
                             * Clicking on an item simulates the positive button
                             * click, and dismisses the dialog.
                             */
                            ListPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
                            dialog.dismiss();
                        }
            });
            这是onPrepareDialogBuilder的源码,因为你在方法里面写super.onPrepareDialogBuilder(builder);所以它直接继承了父类的方法,所以改变不了,但是如果你要把这句话删除,就可以自己写dialog了,但是ListPreference的数据有读不出来了,你自己可以试试,,,
      

  8.   

    本来我想这样写的builder=new AlertDialog.Builder(new ContextThemeWrapper(context1, R.style.AlertDialogCustom));,但是没用读出xml的数据,,,
      

  9.   

    public class ListPreferenceEx extends ListPreference
    {
    Context context1;
    View menuView;
    public ListPreferenceEx(Context context, AttributeSet attrs)
    {
    super(context, attrs);
    context1=context;
    } @Override
    protected void onPrepareDialogBuilder(AlertDialog.Builder builder)
    {
    //Builder builder1=new AlertDialog.Builder(new ContextThemeWrapper(context1, R.style.AlertDialogCustom));
    //super.onPrepareDialogBuilder(builder); // To change body of overridden
    // methods use File | Settings |
    // File Templates.
    //builder=new AlertDialog.Builder(new ContextThemeWrapper(context1, R.style.AlertDialogCustom));
    menuView = View.inflate(context1, R.layout.add_tab, null);
    /*builder.setNegativeButton(null, null);
    builder.setTitle(null);*/
    builder.setView(menuView);



    }
    }这是我改写你的代码,显示出我想要的dialog,但是ListPreference就没有读取xml的数据,,,
      

  10.   

    那我就不读xml的数据,直接在这里硬编码设置数据啊?只要能实现效果就可以LS帮忙再改改,能实现吗?
      

  11.   

    已经帮你改了呗,menuView = View.inflate(context1, R.layout.add_tab, null);和builder.setView(menuView);这里就是显示你想要的dialog,,,
      

  12.   

    R.layout.add_tab这个xml怎样写呢,LS好人做到底呀。