开发者

Refreshing the display from a widget?

I am trying to set the screen brightness from a widget. We know this is easily possible since tons of widgets do this already, but how.....

In a service I call from the widget I do this to set the brightness:

Settings.System.putInt(this.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 200);

That works great except it does not "refresh" the screen to apply the new settings. Turning the screen off and on does refresh the display settings, so we know that the code works.

I also read on several sites that something like this will refresh the screen, but we cannot use this since we are in a widget. The widget activity and the service cannot use getWindow.

WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 100 / 100.0f;
getWindow().setAttributes(lp);

How else are all these widgets like Beautiful Widgets, Power control, Extended controls, etc doing this?

Update: Another poster recommended kicking off an empty activity and executing the WindowManager refres开发者_C百科h. That works but it brings up an ugly black screen for a second. Since the other widgets don't do this, there has to be a way to keep the ugly blank black screen from showing.


For the blackscreen, set a theme on the activity, containing this:

<style name="Theme.Transparent" parent="android:Theme"> 
<item name="android:windowIsTranslucent">true</item> 
<item name="android:windowBackground">@color/transparent</item> 
<item name="android:windowContentOverlay">@null</item> 
<item name="android:windowNoTitle">true</item> 
<item name="android:windowIsFloating">true</item> 
<item name="android:backgroundDimEnabled">false</item> 
</style>

Thanks Sebastian for the answer, I've copied it in here.


Shameless copy&paste from Changing the Screen Brightness System Setting Android

android:theme="@android:style/Theme.Translucent.NoTitleBar"

does it all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜