我是 android 开发的新手,我想弄清楚我如何制作一个按钮来保存 Activity 中的更改。简介:我有一个 seekBar,我可以在其中更改铃声音量,但它会直接更改系统,我放了一个按钮来保存更改,我不知道该怎么做。这是我的代码:
主要的.xml
<Button
android:id="@+id/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_text"/>
<SeekBar
android:id="@+id/seekVolume"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
活动
public class SaveActivity extends Activity {
private AudioManager aManager;
private SeekBar seekVolume;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
aManager = (AudioManager) getSystemService(AUDIO_SERVICE);
Button save = (Button) findViewById(R.id.save);
setOnClickListener();
}
private void setOnClickListener(){
SeekBar seekVolume = (SeekBar) findViewById(R.id.seekVolume);
seekVolume.setMax(aManager.getStreamMaxVolume(AudioManager.STREAM_RING));
seekVolume.setKeyProgressIncrement(1);
seekVolume.setProgress(aManager.getStreamVolume(AudioManager.STREAM_RING));
seekVolume.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar ringvolume) {
}
public void onStartTrackingTouch(SeekBar ringvolume) {
}
public void onProgressChanged(SeekBar ringvolume, int progress,boolean fromUser) {
aManager.setStreamVolume(AudioManager.STREAM_RING, progress, AudioManager.FLAG_SHOW_UI + AudioManager.FLAG_PLAY_SOUND);
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
if(keyCode==KeyEvent.KEYCODE_VOLUME_DOWN || keyCode==KeyEvent.KEYCODE_VOLUME_UP){
seekVolume.setProgress(aManager.getStreamVolume(AudioManager.STREAM_RING));
}
return (super.onKeyDown(keyCode, event));
}
}
我真的不知道该怎么做。多谢你们!