调整屏幕显示亮度

简介: 使用SeekBar控件来控制 布局文件:   Activity代码 1.设置SeekBar控件 SeekBar bar = (SeekBar) findViewById(R.

使用SeekBar控件来控制

布局文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                tools:context=".MainActivity">

    <!-- 拖拽实现控制屏幕亮度-->
    <SeekBar
            android:id="@+id/brightness_bar"
            android:layout_width="400dp"
            android:layout_height="wrap_content"
            />
</LinearLayout>

 

Activity代码

1.设置SeekBar控件

SeekBar bar = (SeekBar) findViewById(R.id.brightness_bar);
        bar.setOnSeekBarChangeListener(this);

2.继承 SeekBar.OnSeekBarChangeListener 接口

实现三个方法

@Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        int id = seekBar.getId();
        Window window = getWindow();
        switch (id){
            //调整屏幕的亮度
            case R.id.brightness_bar:
                WindowManager.LayoutParams attributes = window.getAttributes();
                attributes.screenBrightness = (float) (progress * 0.01);
                window.setAttributes(attributes);
                break;
        }
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
    }

 

目录
打赏
0
0
0
0
7
分享
相关文章
VS2019显示器颜色调整成护眼模式的颜色
工具 -> 选项 -> 环境 -> 字体和颜色,显示项为“纯文本”,设置项背景色:色调=85,饱和度=123,亮度=205,或者 rgb为199,238,206
USB摄像头设置采集亮度和对比度
USB摄像头设置采集亮度和对比度
478 0
USB摄像头设置采集亮度和对比度
LabVIEW自适应屏幕分辨率缩放
在使用 LabVIEW进行上位机项目开发的时候软件的分辨率是根据我们所开发的电脑所决定的,但是当开发完的上位机软件运行在其他分辨率较高或者较低的电脑上时可能会出现比例不合适而导致变形。
432 0
【OpenGL】二十二、OpenGL 光照效果 ( 模型准备 | 光照设置 | 启用光照 | 启用光源 | 设置光源位置 | 设置光照参数 | 设置环境光 | 设置反射材质 | 设置法线 )(二)
【OpenGL】二十二、OpenGL 光照效果 ( 模型准备 | 光照设置 | 启用光照 | 启用光源 | 设置光源位置 | 设置光照参数 | 设置环境光 | 设置反射材质 | 设置法线 )(二)
289 0
【OpenGL】二十二、OpenGL 光照效果 ( 模型准备 | 光照设置 | 启用光照 | 启用光源 | 设置光源位置 | 设置光照参数 | 设置环境光 | 设置反射材质 | 设置法线 )(二)
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等