SeekBar seekBar = (SeekBar) findViewById (R. id. seekBar );
// The maximum brightness of the progress bar. The value 255 indicates the maximum brightness.
SeekBar. setMax (255 );
// Obtain the current brightness
Int normal = Settings. System. getInt (getContentResolver (),
Settings. System. SCREEN_BRIGHTNESS, 255 );
// Bind the progress bar to the current brightness
SeekBar. setProgress (normal );
SeekBar. setOnSeekBarChangeListener (new OnSeekBarChangeListener (){
@ Override
Public void onStopTrackingTouch (SeekBar seekBar ){
// Get the current progress
Int tmpInt = seekBar. getProgress ();
// When the progress is less than 80, set it to 80 to prevent the consequences from being too dark.
If (tmpInt <80 ){
TmpInt = 80;
}
// Adjust the brightness based on the current progress
Settings. System. putInt (getContentResolver (),
Settings. System. SCREEN_BRIGHTNESS, tmpInt );
TmpInt = Settings. System. getInt (getContentResolver (),
Settings. System. SCREEN_BRIGHTNESS,-1 );
WindowManager. LayoutParams wl = getWindow (). getAttributes ();
Float tmpFloat = (float) tmpInt/255;
If (tmpFloat> 0 & tmpFloat <= 1 ){
Wl. screenBrightness = tmpFloat;
}
GetWindow (). setAttributes (wl );
}
@ 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
}
});