zoukankan      html  css  js  c++  java
  • Android app设置全屏模式

    Android中,为APP设置全屏模式,主要有如下几种方式:

    在manifest中设置

    在项目中找到AndroidManifest.xml配置文件,找到Activity所在的节点,添加theme。

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.name.test"
          android:versionCode="1"
          android:versionName="1.0">
        <uses-sdk android:minSdkVersion="8" />
    
        <application android:icon="@drawable/icon" android:label="@string/app_name">
            <activity android:name=".MainActivity"
                      android:label="@string/app_name" android:screenOrientation="landscape"
                      android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
                      <!--换成android:theme="@android:style/Theme.NoTitleBar" 亦可-->
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
        </application>
    </manifest>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    其中,android:screenOrientation=”landscape”是修改Android手机的屏幕方向 
    android:theme=”@android:style/Theme.NoTitleBar.Fullscreen”是设置主题,即没有标题并且全屏

    在MainActivity中设置

    在onCreate入口函数中通过setTheme()方法设置主题,setRequestedOrientation()方法设置屏幕方向。

    public void onCreate(Bundle savedInstanceState){
        setTheme(style.Theme_Black_NoTitleBar_Fullscreen);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    另外,也可以使用requestWindowFeature()设置是否显示标题,setFlags()方法设置全屏。但此方法明显能看到title bar显示了之后又消失了,用户体验不好。

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    • 1
    • 2
    • 3
    • 4

    配置Style + Manifest

    首先,在res/values文件夹下创建或修改styles.xml文件

    <?xmlversion="1.0" encoding="utf-8"?> 
    <resources>
        <style name="NoTitle" parent="android:Theme">
            <item name="android:windowNoTitle">true</item>
        </style> 
    </resources> 
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    然后,修改AndroidManifest.xml

    <activity
        android:label="@string/app_name"
        android:theme="@style/NoTitle" />

    Android中,为APP设置全屏模式,主要有如下几种方式:

    在manifest中设置

    在项目中找到AndroidManifest.xml配置文件,找到Activity所在的节点,添加theme。

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.name.test"
          android:versionCode="1"
          android:versionName="1.0">
        <uses-sdk android:minSdkVersion="8" />
    
        <application android:icon="@drawable/icon" android:label="@string/app_name">
            <activity android:name=".MainActivity"
                      android:label="@string/app_name" android:screenOrientation="landscape"
                      android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
                      <!--换成android:theme="@android:style/Theme.NoTitleBar" 亦可-->
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
        </application>
    </manifest>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    其中,android:screenOrientation=”landscape”是修改Android手机的屏幕方向 
    android:theme=”@android:style/Theme.NoTitleBar.Fullscreen”是设置主题,即没有标题并且全屏

    在MainActivity中设置

    在onCreate入口函数中通过setTheme()方法设置主题,setRequestedOrientation()方法设置屏幕方向。

    public void onCreate(Bundle savedInstanceState){
        setTheme(style.Theme_Black_NoTitleBar_Fullscreen);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    另外,也可以使用requestWindowFeature()设置是否显示标题,setFlags()方法设置全屏。但此方法明显能看到title bar显示了之后又消失了,用户体验不好。

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    • 1
    • 2
    • 3
    • 4

    配置Style + Manifest

    首先,在res/values文件夹下创建或修改styles.xml文件

    <?xmlversion="1.0" encoding="utf-8"?> 
    <resources>
        <style name="NoTitle" parent="android:Theme">
            <item name="android:windowNoTitle">true</item>
        </style> 
    </resources> 
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    然后,修改AndroidManifest.xml

    <activity
        android:label="@string/app_name"
        android:theme="@style/NoTitle" />
  • 相关阅读:
    linux shell创建目录、遍历子目录
    linux shell写入单行、多行内容到文件
    如何起个好名字
    linux shell编程中的数组定义、遍历
    详解浏览器分段请求基础——Range,助你了解断点续传基础
    实现一个大文件上传和断点续传
    localStorage设置过期时间
    Python3 __slots__
    Nginx 流量统计分析
    argparse简要用法总结
  • 原文地址:https://www.cnblogs.com/DreamRecorder/p/9216423.html
Copyright © 2011-2022 走看看