Button btn_vol = (Button) findViewById(R.id.btn_vol);
btn_vol.setOnClickListener(new View.OnClickListener() { //볼륨설정 ,
@Override
public void onClick(View v) {
View innerView = getLayoutInflater().inflate(R.layout.seek_bar, null);
AlertDialog.Builder adialog = new AlertDialog.Builder(
PlayListActivity.this);
adialog.setView(innerView);
seekVolumn = (SeekBar) innerView.findViewById(R.id.SeekBar_Volumn);
setSeekbar();
AlertDialog alert = adialog.create();
alert.setTitle("볼륨설정");
alert.show();
}
});
private void setSeekbar(){
final AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
int nMax = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int nCurrentVolumn = audioManager
.getStreamVolume(AudioManager.STREAM_MUSIC);
seekVolumn.setMax(nMax);
seekVolumn.setProgress(nCurrentVolumn);
seekVolumn.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
progress, 0);
}
});
}
seek_bar.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="30dip" >
<SeekBar
android:id="@+id/SeekBar_Volumn"
android:layout_width="200dip"
android:layout_height="wrap_content" />
</LinearLayout>
'안드로이드' 카테고리의 다른 글
android nfc url read/write (0) | 2014.12.30 |
---|---|
ListView did not receive a notification 오류 해결법 (0) | 2014.11.13 |
Android GCM JSP 연동 예제 (2) (1) | 2014.08.20 |
Android GCM JSP 연동 예제 (1) (0) | 2014.08.19 |
android 웹 서버에 있는 이미지 다운받고 실행하기 (0) | 2014.07.16 |