Here again, i will going to show you another tutorial pertaining the
seekbar in android, if you follow my previous post I show there on how to change screen brightness in android by sliding the seekbar in the activity.
Now i will be going to show you on how to put seekbar in alertdialog, yeah! you read it right! So lets Start!
In layout folder copy this code and paste it into your
activity_main.xml
And in your MainActivity.java copy this code:
import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.SeekBar; import android.widget.TextView; public class MainActivity extends Activity { public TextView txtView; float curBrightnessValue = 0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txtView = (TextView)findViewById(R.id.textView1); // TextView // Button1 final Button btn1 = (Button) findViewById(R.id.button1); btn1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ShowDialog(); } }); } public void ShowDialog(){ final AlertDialog.Builder popDialog = new AlertDialog.Builder(this); final SeekBar seek = new SeekBar(this); seek.setMax(255); seek.setKeyProgressIncrement(1); popDialog.setIcon(android.R.drawable.btn_star_big_on); popDialog.setTitle("Please Select Into Your Desired Brightness "); popDialog.setView(seek); seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){ txtView.setText("Value of : " + progress); } public void onStartTrackingTouch(SeekBar arg0) { //do something // TODO Auto-generated method stub } public void onStopTrackingTouch(SeekBar seekBar) { //do something } }); // Button OK popDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); popDialog.create(); popDialog.show(); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } }Thats it! Now Run it!
You may also like:
Change the screen brightness using alert dialog with seek bar examplehttp://programondaspot.blogspot.com/2015/09/change-screen-brightness-using-alert.html