当前位置: 代码迷 >> Android >> Android荧屏亮度调节
  详细解决方案

Android荧屏亮度调节

热度:93   发布时间:2016-05-01 14:44:24.0
Android屏幕亮度调节
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			}		});

  相关解决方案