如何为所有活动设置方向固定 [英] How can I set Orientation Fixed for all activities

查看:20
本文介绍了如何为所有活动设置方向固定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

安卓布局.如何为 AndroidMainfest.xml 的应用程序标签中的所有活动设置 Orientation Fixed?我不想单独为每个活动设置方向.提前致谢.

Android Layout. How can I set Orientation Fixed for all activities in application Tag of AndroidMainfest.xml ? I don't want to set orientation for each activity individually. Thanks in advance.

推荐答案

GoogleIO 应用有一个 ActivityHelper 类.它有一个名为 initialize() 的静态方法,它处理每个 Activity 发生的很多事情.然后您只需要记住 onCreate() 方法中的 1 行代码,它可以处理设置该值以及每个活动所需的其他几个值.

The GoogleIO app has a ActivityHelper class. It has a static method called initialize() which handles a lot things that happen for every Activity. Then it is just 1 line of code in the onCreate() method that you need to remember, that could handle setting that value and several others that are necessary for each activity.

没有导入或类似的东西.创建一个名为 ActivityHelper 的类

No importing or anything like that. Create a class called ActivityHelper

public class ActivityHelper {
    public static void initialize(Activity activity) {
        //Do all sorts of common task for your activities here including:

        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
}

然后在你所有的活动中调用 onCreate() 方法 ActivityHelper.initialize()如果您还计划开发表格,您可能需要考虑使用:

Then in all of your activies onCreate() method call ActivityHelper.initialize() If you are planning on developing for tables as well you may want to consider using:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

我在此处

抱歉...您需要传递活动.看上面的代码

Sorry... you need to pass the the Activity. see the code above

这篇关于如何为所有活动设置方向固定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆