private void getzitidaxiao() { // 创建数据 final String[] titlle2 = new String[]{"小", "中", "大", "特大"}; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("字体大小") .setSingleChoiceItems(titlle2, 0, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub if (which == 0) { textzt.setText(titlle2[which]); getSharedPreferences("ALER", MODE_PRIVATE).edit().putInt("font", 0).commit(); alertDialog.dismiss(); } else if (which == 1) { textzt.setText(titlle2[which]); getSharedPreferences("ALER", MODE_PRIVATE).edit().putInt("font", 1).commit(); alertDialog.dismiss(); } else if (which == 2) { textzt.setText(titlle2[which]); getSharedPreferences("ALER", MODE_PRIVATE).edit().putInt("font", 2).commit(); alertDialog.dismiss(); } if (which == 3) { textzt.setText(titlle2[which]); getSharedPreferences("ALER", MODE_PRIVATE).edit().putInt("font", 3).commit(); alertDialog.dismiss(); } } }); builder.setPositiveButton("取消", null); alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(true); alertDialog.show(); }
适配器 tv要更改的TextView
if (anInt == 0) { tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, 15); //设置45PX notifyDataSetChanged(); } else if (anInt == 1) { tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30); //设置45SP notifyDataSetChanged(); } else if (anInt == 2) { tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 46); //设置45SP notifyDataSetChanged(); } else if (anInt == 3) { tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 58);//设置45DIP notifyDataSetChanged(); }
获取
int anInt = context.getSharedPreferences("ALER",MODE_PRIVATE).getInt("font", 0);