当前位置:   article > 正文

Android 设置屏幕亮度_android 命令设置背光 settings

android 命令设置背光 settings

使用SeekBar调节屏幕亮度,代码如下:

    /**
     * 设置屏幕亮度
     */
    private void setBrighrnessSeekBar() {
        brightnessSeekBar = (SeekBar) findViewById(R.id.BrightnessSeekBar);
        brightnessSeekBar.setMax(255);
        brightnessSeekBar.setProgress((int) (android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS, 255)));
        brightnessSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                if (fromUser) {
                    Integer itg = brightnessSeekBar.getProgress();
//                    System.out.println("当前亮度------------------>"+itg+"____"+(itg*100/255));
                    //设置当前activity的屏幕亮度
                    WindowManager.LayoutParams lp = MySettings.this.getWindow().getAttributes();
                    //0到1,调整亮度暗到全亮
                    lp.screenBrightness = Float.valueOf(itg / 255f);
                    MySettings.this.getWindow().setAttributes(lp);
                    //保存为系统亮度
                    android.provider.Settings.System.putInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS, itg);

                }
            }

            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/神奇cpp/article/detail/1000636
推荐阅读
相关标签
  

闽ICP备14008679号