Disable window and transition settings

匿名 (未验证) 提交于 2019-12-03 02:29:01

问题:

So what I need to do is toggle window and/or transition animations on and off in code, to have the same effect of going Settings > Display > Animations > Disable all animations.

The way I am familiar with changing device settings is by using a ContentResolver within the Settings.System.putInt() method as follows:

ContentResolver cr = getContentResolver(); Settings.System.putInt(cr, Settings.System.WINDOW_ANIMATION_SCALE, 0); 

As described in the documentation 'Setting to 0 will disable all .... animations' for both settings. When reading the setting before and after using the putInt() method, using this:

Settings.System.getString(cr, Settings.System.WINDOW_ANIMATION_SCALE); 

I can see that the setting is being changed. However when then doing something to begin a window or transition animation it is obvious to see that the setting hasn't made any difference and the transition still occurs.

I would also like to say that when I change the setting from within the Settings screen, I can see that the setting has been changed when I rerun my application. So it seems this is the correct setting and that my application isn't changing it correctly.

Is there something else I'm missing?

Thanks in advance.

回答1:

Check you are setting the correct scales.

Settings.System.TRANSITION_ANIMATION_SCALE  

Will change the Activity transitions.

Where as:

Settings.System.WINDOW_ANIMATION_SCALE 

Will effect the Window animations such as Dialogs opening.

(Added API16) This will enable/disable View specific animations.

Settings.System.ANIMATOR_DURATION_SCALE 

Also I'm pretty sure these are floats as these can be 0.5x animation settings meaning half speed. I have never tried these from an App before.

But two things come to mind:

  • The ContentProvider is asynchronous, and you will need to listen to the Setting to finished being set
  • Also that these will probably not work until you create/finish and activity. meaning changing them mid activity might not effect the current Activity, but I will have to test that theory.


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!