最終更新:
moonlight_aska 2013年08月01日(木) 22:47:33履歴
アプリケーション画面の明るさを変更するには, WindowManager.LayoutParamsクラスを利用する.


- ScreenBrightness.java
- WindowManager#getWindowメソッドで, LayoutParamsのインスタンスを取得する.
- 初期値(0.0〜1.0)を代入する.
- WindowManager#setWindowメソッドで, LayoutParamsを設定する.
package com.moonlight_aska.android.screenbrightness;
import android.os.Bundle;
import android.app.Activity;
import android.view.WindowManager.LayoutParams;
import android.widget.TextView;
public class ScreenBrightness extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// LayoutParamsのインスタンスを取得
LayoutParams lp = getWindow().getAttributes();
// 明るさを設定
lp.screenBrightness = 0.8F;
getWindow().setAttributes(lp);
TextView text = (TextView)findViewById(R.id.text_label);
text.setText("明るさ:" + String.valueOf(lp.screenBrightness));
}
}
コメントをかく