T
T
Tatevik122019-02-07 19:26:44
Android
Tatevik12, 2019-02-07 19:26:44

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?
5c5c5b915d433836720192.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Varakosov, 2019-02-07
@thelongrunsmoke

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);

Completely, the code will look something like this:
В xml, определить максимум для SeekBar
В активити, повешать листенер.
((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 question

Ask a Question

731 491 924 answers to any question