我從存儲文本大小和文本的書中摘取了示例程序。當我再次運行程序時,文本大小正在減小。誰能幫我出我的新到Android字體大小未保存在SharedPreferences中
public void onClick(View v) {
//Getting the SharedPreference object
prefs = getSharedPreferences(prefName, MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
// save the values in the EditText view to preferences
editor.putFloat(FONT_SIZE_KEY, editText.getTextSize());
editor.putString(TEXT_VALUE_KEY, editText.getText().toString());
// Saves the values
editor.commit();
//Display file saved message
Toast.makeText(getBaseContext(), "Font size saved Successfully!", Toast.LENGTH_SHORT).show();
}
});
//加載的共享對象Prefernces
SharedPreferences prefs = getSharedPreferences(prefName, MODE_PRIVATE);
// Set the TextView font size to the previously saved values
float fontSize = prefs.getFloat(FONT_SIZE_KEY, 12);
// init the SeekBar and EditText
seekBar.setProgress((int)fontSize);
editText.setText(prefs.getString(TEXT_VALUE_KEY, ""));
editText.setTextSize(seekBar.getProgress());
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar arg0, int progress, boolean arg2) {
// Change the font size of the EditText
editText.setTextSize(progress);
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
}
@Override
public void onStopTrackingTouch(SeekBar arg0) {
}
});
對不起。不工作... – Pramod
好的,添加了更完整的解決方案。 – dragonroot