使用样式设置活动屏幕方向

发布于 2024-12-15 00:34:05 字数 589 浏览 3 评论 0原文

我正在尝试使用样式设置活动屏幕方向:

这是 styles.xml:

...
<style name="Some.Activity" parent="android:Theme">
  <item name="android:screenOrientation">portrait</item>
</style>
...

这是 AndroidManifest.xml 中的活动声明:

<activity android:name="SomeActivity" android:theme="@style/Some.Activity"/>

但它不起作用。
我知道我可以

<activity android:name="SomeActivity" android:theme="@style/Some.Activity"
    android:screenOrientation="..."/>

在清单中设置,但使用主题来做到这一点对我来说很重要。
有想法吗?

I'm trying to set activity screen orientation using a styles:

Here is the styles.xml:

...
<style name="Some.Activity" parent="android:Theme">
  <item name="android:screenOrientation">portrait</item>
</style>
...

and here is activity declaration in AndroidManifest.xml:

<activity android:name="SomeActivity" android:theme="@style/Some.Activity"/>

and it doesn't work.
I know that I can just set

<activity android:name="SomeActivity" android:theme="@style/Some.Activity"
    android:screenOrientation="..."/>

in the manifest, but its important to me to do that using a theme.
Ideas?

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

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

发布评论

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

评论(2

淡墨 2024-12-22 00:34:05

http://developer.android.com/guide/practices/screens_support.html

此链接可能有帮助。基本上,您必须为每个方向制作不同的布局文件,并将它们放入相应的布局土地或布局端口文件夹中。您还可以为不同屏幕尺寸上的不同方向创建布局。例如,如果横向模式下“正常”尺寸屏幕的所有控件不适合小屏幕,您可以创建一个名为layout-small-land 的文件夹并拥有另一个自定义布局文件。

http://developer.android.com/guide/practices/screens_support.html

This link may help. Basically you have to make different layout files for each orientation and put them in corresponding layout-land or layout-port folders. You can also create layouts for different orientations on different screen sizes. For example, if not all of the controls you have for a "normal" sized screen in landscape mode fit on a small screen you can create a folder named layout-small-land and have another customized layout file.

野の 2024-12-22 00:34:05

在这里修改我的答案:这似乎不受支持,并非所有属性都是样式属性。

Revising my answer here: this seems not to be supported, not all attributes are styled ones.

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