【发布时间】:2020-07-04 12:01:15
【问题描述】:
如何使用手机方向来调整屏幕亮度?例如,纵向时亮度最大,横向时亮度最小。
【问题讨论】:
-
我可以在纵向设置屏幕亮度,然后在横向设置最小亮度吗?
标签: android android-orientation screen-brightness
如何使用手机方向来调整屏幕亮度?例如,纵向时亮度最大,横向时亮度最小。
【问题讨论】:
标签: android android-orientation screen-brightness
在您的活动类中使用以下方法:(检查方向并控制亮度)
@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" />
【讨论】:
cResolver = getContentResolver(); Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS_MODE,SCREEN_BRIGHTNESS_MODE_AUTOMATIC); 自动