Android 设置亮度

设置当前Activity中的亮度,退出Activity后恢复系统默认亮度。


未测试系统改变亮度后Activity亮度是否改变。


package com.ltc.screen;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class Actmain extends Activity {
	
	private TextView textView;
	private Button button;
	
	float f = 1.0f;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        textView = (TextView)findViewById(R.id.textview);
        button = (Button)findViewById(R.id.btn);
        button.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				f -= 0.1f;
				
				//f 不能 为0 ,为0就锁屏了。
				if(f < 0.0001f){
					f = 1.0f;
				}
				
				setBrightness(f);
			}
		});
    }
    
    
    private void setBrightness(float f){
    	WindowManager.LayoutParams lp = getWindow().getAttributes();
		lp.screenBrightness = f;   
		getWindow().setAttributes(lp);
    }
}


你可能感兴趣的:(android,测试,Class,float,button)