zoukankan      html  css  js  c++  java
  • Android基础教程——调节系统屏幕亮度

    import android.app.Activity;
    import android.content.ContentResolver;
    import android.provider.Settings;
    import android.provider.Settings.SettingNotFoundException;
    import android.view.WindowManager;
    
    public class ScreenBrightness {
    
    	public static int getScreenBrightness(Activity activity) {
    		int value = 0;
    		ContentResolver cr = activity.getContentResolver();
    		try {
    			value = Settings.System.getInt(cr,
    					Settings.System.SCREEN_BRIGHTNESS);
    		} catch (SettingNotFoundException e) {
    
    		}
    		return value;
    	}
    
    	public static void setScreenBrightness(Activity activity, int value) {
    		WindowManager.LayoutParams params = activity.getWindow()
    				.getAttributes();
    		params.screenBrightness = value / 255f;
    		activity.getWindow().setAttributes(params);
    	}
    }
    
    


    此类直接调用系统功能来调节屏幕参数!
    注意如果调用

    setScreenBrightness()
    

    方法时传入的value值为0,那屏幕就全暗了,然后你的设备就一直暗着,直到重新启动系统了,所以在调用前最好先对传值进行下处理

  • 相关阅读:
    2013.11.18 流水
    return to blog!
    IOS实现毛玻璃效果的三种方式
    UI常用控件总结(三)
    UI常用控件总结(二)
    UI常用控件总结(一)
    UIView 常见属性
    OC语言BLOCK和协议
    OC语言类的深入和分类
    OC语言构造方法
  • 原文地址:https://www.cnblogs.com/smallerpig/p/3646098.html
Copyright © 2011-2022 走看看