我的申请有问题
layout: main.xml
,它包含一个名为“设置”的按钮setContentView(R.layout.setting);
转到setting.xml
setting.xml
中,我有一个搜索栏来控制应用程序的数量我已关注此帖“Using SeekBar to Control Volume in android?”
我在activity_main
中喜欢这样,但是当我更改搜索栏时没有任何反应
答案 0 :(得分:0)
以下是代码:
//control volume using seek bar in Setting
private AudioManager audiomanager = null;
private SeekBar seekbar = null;
// SoundStatus
private TextView soundstatus = null;
// check Sound on
private boolean soundon = true;
// control Background Sound
private MediaPlayer mp = null;
// Sound icon
private ImageView sound = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
setContentView(R.layout.activity_main);
// Background music when the app launch
// music in raw folder
mp = MediaPlayer.create(this, R.raw.backgroundsound);
mp.start();
mp.setLooping(true);
// Control volume
ControlVolume();
}
...
...
...
public void ControlVolume()
{
seekbar = (SeekBar)findViewById(R.id.seekBar);
audiomanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
seekbar.setMax(audiomanager
.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
seekbar.setProgress(audiomanager
.getStreamVolume(AudioManager.STREAM_MUSIC));
seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
@Override
public void onStopTrackingTouch(SeekBar arg0)
{
}
@Override
public void onStartTrackingTouch(SeekBar arg0)
{
}
@Override
public void onProgressChanged(SeekBar arg0, int progress, boolean arg2)
{
audiomanager.setStreamVolume(AudioManager.STREAM_MUSIC,
progress, 0);
}
});
}
这是MainActivity.java 主要布局包括按钮设置 并且搜索栏处于设置布局