Android Activity,如何使用Java代码覆盖manifest的android:configChanges?

发布于 12-02 00:53 字数 194 浏览 5 评论 0原文

我正在编写一个自定义 Activity 类(将其用作其他 Activity 类的超类),它覆盖了许多默认功能。我想要的功能之一是方向处理,虽然我可以做到,但它需要

android:configChanges="orientation"

在清单中。有没有办法在 java 代码中强制执行与上面一行相同的操作?

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"

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

盗心人2024-12-09 00:53:07

您仍然需要在 XML 中包含该属性,但也可以在 Java 中处理它;请参阅我的博客文章: http:// c0deattack.wordpress.com/2010/12/25/dealing-with-screen-orientation-changes-manually/

编辑:您无法设置 configChanges 属性以编程方式。我想这与创建活动的方式有关。它们首先从 XML 创建,然后调用活动实现中的重写方法。 API 中没有任何内容可以让您更改 configChanges 属性。

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/

Edit: 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.

完美的未来在梦里2024-12-09 00:53:07

您可以在“android:configChanges”中添加所有可能的值,并覆盖 Activity 中的方法 onConfigurationChanged,但仅针对您需要的情况调用 Activity.receate()

You can add all possible value in "android:configChanges",and override method onConfigurationChanged in Activity,but only call Activity.receate() for the case you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文