2011-09-26 5 views
3

화면 밝기를 설정하려고하는데 this.getWindow()로 현재 창을 가져 오면 null이됩니다. 왜 이런거야? setBrightness() 메서드에 모든 코드를 게시합니다.안드로이드 폰에서 화면 밝기를 설정하려고합니다.

System.putInt(getContentResolver(), System.SCREEN_BRIGHTNESS, 
      brightness); 
Window window = getWindow(); 
WindowManager.LayoutParams lp = window.getAttributes(); 
lp.screenBrightness = brightness/(float) 255; 
window.setAttributes(lp); 
+0

당신은'OnClickListener()'또는 유사하게'getWindow()'를 호출하고 있습니까? –

+0

활동 아니요. 활동이 표시되지 않고 메소드가 기본 활동 클래스에서 통지를 수신하는 다른 클래스에서 호출됩니다. 실제로 정상적인 클래스가되기를 원했지만 getWindow() 메소드에 액세스 할 수 있도록해야만하는 것처럼 보였습니다. – plast

+0

여기에 당신을 도울 수있는 간단한 방법입니다 http://stackoverflow.com/questions/2937365/increasing-screen-brightness-for-activity/21829712#21829712 –

답변

0

System.putInt()를 사용하지 마십시오. 이미 lp!

다음 코드는 작동 : 당신이 SeekBar를를 사용하는 경우

Window window = getWindow(); 
float brightness = 100.0f; 
WindowManager.LayoutParams lp = window.getAttributes(); 
lp.screenBrightness = brightness/255.0f; 
window.setAttributes(lp); 
+0

입력 해 주셔서 감사합니다! 그래도 getWindow()에서 null이 나옵니다. 어쩌면 내가 틀린 창을 어쩌면 가져 오는거야? – plast

+0

수입을 확인하십시오 android.view.Window – Houcine

+0

다음은 내보기 가져 오기입니다 : import android.view.Window; import android.view.WindowManager; – plast

0

는이 라인을 시도,

System.putInt(cResolver, System.SCREEN_BRIGHTNESS, brightness); 
LayoutParams layoutpars = window.getAttributes(); 
layoutpars.screenBrightness = brightness/(float)255; 
window.setAttributes(layoutpars); 
0

당신이 이런 식으로하여 GetWindow 전에 getActivity을()() 추가 조각에서 호출하는 경우

getActivity().getWindow().setAttributes(layoutParams); 

seekbar를 사용하면 브이그를 0으로 설정하면 화면이 완벽해질 수 있습니다 어둠 (on android 2.3)

관련 문제