Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set screen brightness in Android

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article is a detailed introduction to "how to set screen brightness in Android". The content is detailed, the steps are clear, and the details are properly handled. I hope this article "how to set screen brightness in Android" can help you solve your doubts. Let's go deeper and learn new knowledge together with the ideas of Xiaobian.

Screen brightness adjustment mode

First of all, it is necessary to clarify that there are two adjustment modes for screen brightness:

Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC: value 1, automatically adjusts brightness.

Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL: value 0, manual mode.

If you need to adjust the brightness, you first need to set the screen brightness adjustment mode to manual mode.

The settings are as follows:

public void setScrennManualMode() { ContentResolver contentResolver = getActivity().getContentResolver(); try { int mode = Settings.System.getInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS_MODE); if (mode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) { Settings.System.putInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); } } catch (Settings.SettingNotFoundException e) { e.printStackTrace(); }}

Get screen brightness values

Here you need to know:

1. The maximum screen brightness is 255.

2. The minimum screen brightness is 0.

3. Screen brightness values must range from 0 to 255.

How to set screen brightness:

private int getScreenBrightness() { ContentResolver contentResolver = getActivity().getContentResolver(); int defVal = 125; return Settings.System.getInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS, defVal);}

Set system screen brightness value

Before setting the brightness of the system screen, you need to ensure that the following permissions are declared in AndroidManifest.xml:

The copy code is as follows:

When the screen brightness mode is 0, i.e. manual adjustment, the screen brightness can be set by the following code:

private void saveScreenBrightness() {setScreennManualMode (); ContentResolver contentResolver = getActivity().getContentResolver(); int value = 255; //Set brightness value to 255 Settings.System.putInt(mContentResolver, Settings.System.SCREEN_BRIGHTNESS, value);}

Set current window brightness

Many video applications, when touch event processing screen brightness, do not modify the system brightness value, but modify the brightness of the window where the current application is located. This is done by modifying the screenBrightness property in LayoutParams. The reference codes are as follows:

private void setWindowBrightness (int brightness) { Window window = getWindow(); WindowManager.LayoutParams lp = window.getAttributes(); lp.screenBrightness = brightness / 255.0f; window.setAttributes(lp);} Read here, this article "How to set screen brightness in Android" article has been introduced, want to master the knowledge points of this article also need to be used by yourself to understand, if you want to know more related content articles, welcome to pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report