Android屏幕亮度調節

[java] 
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 
            } 
        }); 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。