我已经能够将自定义字体应用于Alert对话框的标题,如下所示:
AlertDialog.Builder builder = new AlertDialog.Builder(this); TextVIEw MyTitle = new TextVIEw(this); MyTitle.setText("My Custom Title"); MyTitle.setTextSize(20); MyTitle.setpadding(5, 15, 5, 5); MyTitle.setGravity(Gravity.CENTER); MyTitle.setTypeface(Typeface.createFromAsset(this.getAssets(), "myFont.ttf")); builder.setCustomTitle(MyTitle);
警报对话框显示由下面一行填充的多选项目列表.
builder.setMultiChoiceItems(MyItems, MycheckedItems, MyDialogListener); //where MyItems is CharSequence[] Array, MycheckedItems => boolean[] array, //MyDialogListener => DialogInterface.OnMultiChoiceClickListener
我也希望将字体应用于这些多选项.我怎样才能做到这一点?可能吗?
解决方法:
AlertDialog.Builder使用AlertController.AlertParams构建对话框.我检查了AlertDialog.Builder #create()调用AlertController.AlertParams #application()如果设置了项目,则创建ListVIEw并分配适配器(AlertParams#createListView()).
我基于createListVIEw源创建了自定义适配器并修改了androID单元格布局:
public static class TypefaceDialog extends DialogFragment { private static final CharSequence[] items = { "A", "B", "C", "D", "E", "F", "G" }; private static final boolean[] checked = { true, false, false, true, true, false, false }; @OverrIDe public Dialog onCreateDialog(Bundle savedInstanceState) { final Typeface FontTypeface = Typeface.createFromAsset(getActivity().getAssets(), "Arial Bold.ttf"); listadapter adapter = new ArrayAdapter<CharSequence>( getActivity(), androID.R.layout.select_dialog_multichoice, androID.R.ID.text1, items) { @OverrIDe public VIEw getVIEw(final int position, VIEw convertVIEw, VIEwGroup parent) { VIEw vIEw = super.getVIEw(position, convertVIEw, parent); CheckedTextVIEw textVIEw = (CheckedTextVIEw)vIEw.findVIEwByID(androID.R.ID.text1); textVIEw.setChecked(checked[position]); textVIEw.setTypeface(FontTypeface); textVIEw.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { CheckedTextVIEw vIEw = (CheckedTextVIEw)v; vIEw.setChecked(!vIEw.isChecked()); checked[position] = vIEw.isChecked(); } }); return vIEw; } }; return new AlertDialog.Builder(getActivity()) .setAdapter(adapter, null) .setPositivebutton("OK", null) .create(); } }
总结 以上是内存溢出为你收集整理的android – 为AlertDialog的MultiSelectItems设置自定义字体(字体)全部内容,希望文章能够帮你解决android – 为AlertDialog的MultiSelectItems设置自定义字体(字体)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)