如何在Android中设置屏幕亮度?

3

我希望有一个对话框,使用 SeekBar 来调整屏幕亮度。

如何显示一个自定义的对话框,其中包含 SeekBar,用于调整屏幕亮度?


3
无法在全局范围内调整屏幕亮度;请注意此StackOverflow问题https://dev59.com/BFfUa4cB1Zd3GeqPKKpD - Aaron McIver
是的,它只会应用于你的窗口。 - Ron
3个回答

6

您可以使用此API。它将更改窗口的屏幕亮度而不是整个系统。

        // Make the screen full bright for this activity.
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.screenBrightness = 1.0f;

        getWindow().setAttributes(lp);

2

这个代码片段应该可以帮助你。

pdlg = ProgressDialog.show(getParent(), "Loading...", ""); 
WindowManager.LayoutParams lp = pdlg.getWindow().getAttributes();
p.dimAmount=0.0f;        //Dim Amount
pdlg.getWindow().setAttributes(lp);  //Applying properties to progress dialog
pdlg.dismiss(); //Dismiss the dialog

1

嘿,你可以像这样设置系统亮度:

 //Set the system brightness using the brightness variable value
System.putInt(cResolver, System.SCREEN_BRIGHTNESS, brightness);
//Get the current window attributes
LayoutParams layoutpars = window.getAttributes();
//Set the brightness of this window
layoutpars.screenBrightness = brightness / (float)255;
//Apply attribute changes to this window
window.setAttributes(layoutpars);

或者您可以参考这个完整的教程


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接