Android的活动,如何覆盖清单的Andr​​oid:configChanges与Java code?清单、Andr、Android、oid

2023-09-13 01:33:06 作者:Winner(冠军)

我编码自定义活动类(使用它作为一个超类为我的其他活动课),它的首要许多默认功能。其中一个功能我想是的方向处理,而我能做到这一点,它需要

I'm coding a custom Activity class (using it as a super class for my other Activity classes) where it's overriding many default functionalities. One of these functionalities I want is orientation handling, and while I can do it, it requires

android:configChanges="orientation"

在清单中。有没有办法强制执行同样的事情线之上,但在Java code?

in the manifest. Is there a way to enforce the same thing as the line above, but in java code?

推荐答案

您仍然需要包括在XML中的属性,但你可以处理它在Java中也;在这里看到我的博客文章:http://c0deattack.word$p$pss.com/2010/12/25/dealing-with-screen-orientation-changes-manually/

You'll still need to include the attribute in the XML but you can handle it in Java too; see my blog post here: http://c0deattack.wordpress.com/2010/12/25/dealing-with-screen-orientation-changes-manually/

编辑:您不能设置configChanges属性编程。我想这是跟在创建活动的方式。他们从XML首先创建,然后在活动的执行被覆盖的方法被调用。没有什么的API,可以让你改变configChanges属性,

You cannot set the configChanges attribute programmatically. I guess it's to do with the way an Activity is created. They're created from the XML first and then the overridden methods in your activity implementation are invoked. There's nothing in the API that lets you change the configChanges attribute.

 
精彩推荐
图片推荐