【问题标题】:Adjust Andriod phone screen brightness using orientation使用方向调整 Android 手机屏幕亮度
【发布时间】:2020-07-04 12:01:15
【问题描述】:

如何使用手机方向来调整屏幕亮度?例如,纵向时亮度最大,横向时亮度最小。

【问题讨论】:

  • 我可以在纵向设置屏幕亮度,然后在横向设置最小亮度吗?

标签: android android-orientation screen-brightness


【解决方案1】:

在您的活动类中使用以下方法:(检查方向并控制亮度)

 @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        // Checks the orientation of the screen
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    Settings.System.putInt(context.getContentResolver(),
               Settings.System.SCREEN_BRIGHTNESS, 0);
        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
                   Settings.System.putInt(context.getContentResolver(),
               Settings.System.SCREEN_BRIGHTNESS, 100);
        }
    }

权限:

<uses-permission
      android:name="android.permission.WRITE_SETTINGS"
      tools:ignore="ProtectedPermissions" />

【讨论】:

  • 感谢您的快速回复!如果我想在纵向时自动亮度怎么办?
  • 我投了赞成票,但我的声望低于 15,因此不会公开显示
  • 没关系。谢谢你。很高兴我能帮上忙。
  • cResolver = getContentResolver(); Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS_MODE,SCREEN_BRIGHTNESS_MODE_AUTOMATIC); 自动
  • 为什么是配置、方向和吐司红?它说无法解析符号?...对不起,我是 Android Studio 的新手,这是我第一次遇到它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多