Answer the question
In order to leave comments, you need to log in
How to make the slider (SeekBar) change brightness (0% -100%) programmatically work?
This slider moves, but does not work on the text . It is
necessary that only in this activity (BookActivity) the brightness changes when reading books. I'm making a reader.
How to do it?
Answer the question
In order to leave comments, you need to log in
There is a universal way to set the screen brightness for a specific activity. Works in all versions.
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = brightness; // Яркость экрана от 0 до 1.
getWindow().setAttributes(lp);
((SeekBar)findViewById(R.id.seekBar)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
float brightness = progress / (float)255;
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = brightness;
getWindow().setAttributes(lp);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question