展会信息港展会大全

android开发屏幕亮度调节
来源:互联网   发布日期:2016-01-19 12:22:28   浏览:2333次  

导读:SeekBar seekBar = (SeekBar) findViewById(R id seekBar); 进度条绑定最大亮度,255是最大亮度seekBar setMax(255); 取得当前亮度int normal = Settings System getInt(getContentResolver(),Sett ...

SeekBar seekBar = (SeekBar) findViewById(R.id.seekBar);

// 进度条绑定最大亮度,255是最大亮度

seekBar.setMax(255);

// 取得当前亮度

int normal = Settings.System.getInt(getContentResolver(),

Settings.System.SCREEN_BRIGHTNESS, 255);

// 进度条绑定当前亮度

seekBar.setProgress(normal);

seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

@Override

public void onStopTrackingTouch(SeekBar seekBar) {

// 取得当前进度

int tmpInt = seekBar.getProgress();

// 当进度小于80时,设置成80,防止太黑看不见的后果。

if (tmpInt < 80) {

tmpInt = 80;

}

// 根据当前进度改变亮度

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

}

});

赞助本站

人工智能实验室
相关内容
AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港