调整Android手机屏幕亮度


贴一段调整安卓手机屏幕亮度的代码 ,可以参考使用,见下:

 public void setBrightness(int level) {
  ContentResolver cr = getContentResolver();
  Settings.System.putInt(cr, "screen_brightness", level);
  try {
   defaultLevel = Settings.System.getInt(cr, "screen_brightness");
  } catch (SettingNotFoundException e) {
   e.printStackTrace();
  }
  Window window = getWindow();
  LayoutParams attributes = window.getAttributes();
  float flevel = level;
  attributes.screenBrightness = flevel / 255;
  getWindow().setAttributes(attributes);
 }

此外,UiModeManager这个类提供了控制系统UI模式的服务,可以参考使用:

{
   UiModeManager uim = (UiModeManager) getSystemService(Context.UI_MODE_SERVICE);
   int i = uim.getCurrentModeType();

   if (i != Configuration.UI_MODE_TYPE_CAR) {
    uim.enableCarMode(0);
   }

   uim.setNightMode(UiModeManager.MODE_NIGHT_YES);

  }

  • 1
  • 2
  • 下一页

相关内容

    暂无相关文章