Android Android屏幕亮度设置
求教关于Android屏幕亮度调节的问题,屏幕亮度分两种,一种是系统的,一种是局限于应用内的,我希望是应用内的调节即可,一款读书软件。
现在有这么几种思路,也是在网上找的,居然都不可以,不知道为什么
一种是
1\. private void brightnessMax() {
2. WindowManager.LayoutParams lp = getWindow().getAttributes();
3. lp.screenBrightness = 1.0f;
4. getWindow().setAttributes(lp);
5. }
再详细一点是
public class MyActivity extends Activity {
/** Called when the activity is first created. */
TextView textView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView = (TextView) findViewById(R.id.MyTextView);
updateToggles();
}
private void updateToggles() {
// TODO Auto-generated method stub
SeekBar seekBar = (SeekBar) findViewById(R.id.MySeekBar);
seekBar.setProgress((int) (android.provider.Settings.System.getInt(
getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS, 255) ));
seekBar.setOnSeekBarChangeListener(seekListener);
}
private OnSeekBarChangeListener seekListener = new OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
if (fromUser) {
Integer tmpInt = seekBar.getProgress();
System.out.println(tmpInt);
// 51 (seek scale) * 5 = 255 (max brightness)
// Old way
android.provider.Settings.System.putInt(getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS,
tmpInt); // 0-255
tmpInt = Settings.System.getInt(getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS, -1);
// Cupcake way..... sucks
WindowManager.LayoutParams lp = getWindow().getAttributes();
// lp.screenBrightness = 1.0f;
// Float tmpFloat = (float)tmpInt / 255;
if (0<= tmpInt && tmpInt <= 255) {
lp.screenBrightness = tmpInt;
}
getWindow().setAttributes(lp);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
// put awesomeness here
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
// and here too
}
};
}这是主程序
http://stackoverflow.com/questions/4544967/get-preferred-screen-brightness-in-android