0
我試圖控制媒體音量DialogPreference中的媒體音量控制器
但總是會在關閉對話框後自動設置爲零。
代碼:
DialogPreference dp = (DialogPreference)findPreference("mediavolume");
dp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
SeekBar volumeBar = (SeekBar)findViewById(R.id.seekbar);
final AudioManager manager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
volumeBar.setMax(manager.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
volumeBar.setProgress(manager.getStreamVolume(AudioManager.STREAM_MUSIC));
volumeBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
manager.setStreamVolume(AudioManager.STREAM_MUSIC, progress,manager.FLAG_PLAY_SOUND);
}
});
return false;
}
});