我想使用拖动条更改编辑框的文本大小。每次我关闭并重新打开活动时,拖动条会自动增加文本大小。以下是代码:
package com.e_orthodoxy.orthodox_prayers;
public class WakeupActivity extends Activity {
private SharedPreferences prefs;
private SeekBar seekbar;
private EditText edittext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wakeup);
seekbar = (SeekBar) findViewById(R.id.seekBar1);
edittext = (EditText) findViewById(R.id.id_wakeup_txt);
prefs = getPreferences(MODE_PRIVATE);
float fs = prefs.getFloat("fontsize", 12);
seekbar.setProgress((int)fs);
edittext.setTextSize(seekbar.getProgress());
seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar){
prefs = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor ed = prefs.edit();
ed.putFloat("fontsize", edittext.getTextSize());
ed.commit();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar){
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser){
edittext.setTextSize(progress);
}
});
}
@Override
public void onBackPressed() {
Intent intent_wakeup_back = new Intent (WakeupActivity.this, DailyPrayersActivity.class);
startActivity(intent_wakeup_back);
finish();
}
}