代码
Button mButton1;
String mDefaultFont1;
SharedPreferences mSharedPreferences1;
SharedPreferences.Editor editor1;
mButton1 = (Button)findViewById(R.id.buttontextfontsent);
mSharedPreferences1 = PreferenceManager.getDefaultSharedPreferences(this);
mDefaultFont1 = mSharedPreferences1.getString("Default_Font1","Normal");
mButton1.setTypeface(mButton1.getTypeface(),Typeface.NORMAL);
mButton1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String[] list = new String[]{"Normal", "Bold", "Italic", "Bold ITalic"};
AlertDialog.Builder builder = new AlertDialog.Builder(CustomizeFont.this);
builder.setTitle("Make your selection");
builder.setItems(list, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if (item==0) mButton1.setTypeface(mButton1.getTypeface(),Typeface.NORMAL);
if (item==1) mButton1.setTypeface(mButton1.getTypeface(),Typeface.BOLD);
if (item==2) mButton1.setTypeface(mButton1.getTypeface(),Typeface.ITALIC);
if (item==3) mButton1.setTypeface(mButton1.getTypeface(),Typeface.BOLD_ITALIC);
editor1 = PreferenceManager.getDefaultSharedPreferences(CustomizeFont.this).edit();
editor1.putString("Default_Font1", String.valueOf(item));
editor1.apply();
}
});
builder.show();
}
});
我可以更改字体,但是当我重新启动 Activity 时,它会恢复到原来的正常字体……问题出在这一行 mButton1.setTypeface(mButton1.getTypeface(),Typeface.NORMAL);
我需要设置TypeFace.NORMAL为Default_Font1但不接受...我该怎么办?
aluckdog
白衣非少年
小怪兽爱吃肉
相关分类