Android中的全屏活动?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2868047/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:40:12  来源:igfitidea点击:

Fullscreen Activity in Android?

androidandroid-activityfullscreenandroid-fullscreen

提问by Praveen

How do I make an activity full screen? I mean without the notification bar. Any ideas?

如何使活动全屏?我的意思是没有通知栏。有任何想法吗?

回答by Cristian

You can do it programatically:

您可以以编程方式执行此操作:

public class ActivityName extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // remove title
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
    }
}

Or you can do it via your AndroidManifest.xmlfile:

或者您可以通过您的AndroidManifest.xml文件来完成:

<activity android:name=".ActivityName"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>

Edit:

编辑:

If you are using AppCompatActivity then you need to add new theme

如果您使用的是 AppCompatActivity 那么您需要添加新主题

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

and then use it.

然后使用它。

<activity android:name=".ActivityName"
    android:label="@string/app_name"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen"/>

Thanks to https://stackoverflow.com/a/25365193/1646479

感谢https://stackoverflow.com/a/25365193/1646479

回答by Dmide

There's a technique called Immersive Full-Screen Modeavailable in KitKat. Immersive Full-Screen Mode Demo

有一种被称为沉浸式全屏模式中可用的奇巧沉浸式全屏模式演示

Example

例子

回答by Ariel Cabib

If you don't want to use the theme @android:style/Theme.NoTitleBar.Fullscreenbecause you are already using a theme of you own, you can use android:windowFullscreen.

如果您不想使用该主题,@android:style/Theme.NoTitleBar.Fullscreen因为您已经在使用您自己的主题,则可以使用android:windowFullscreen.

In AndroidManifest.xml:

在 AndroidManifest.xml 中:

<activity
  android:name=".ui.activity.MyActivity"
  android:theme="@style/MyTheme">
</activity>

In styles.xml:

在styles.xml中:

<style name="MyTheme"  parent="your parent theme">
  <item name="android:windowNoTitle">true</item>
  <item name="android:windowFullscreen">true</item> 
</style>

回答by iNFInite PosSibiLitiEs

In AndroidManifest.xmlfile:

AndroidManifest.xml文件中:

<activity
    android:name=".Launch"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > <!-- This line is important -->

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>  

Or in Javacode:

或者在Java代码中:

protected void onCreate(Bundle savedInstanceState){
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

回答by Bala Vishnu

If your using AppCompat and ActionBarActivity, then use this

如果您使用 AppCompat 和 ActionBarActivity,则使用此

getSupportActionBar().hide();

getSupportActionBar().hide();

回答by jiahao

Be careful with

小心

requestWindowFeature(Window.FEATURE_NO_TITLE);

If you are using any method to set the action bar as the follow:

如果您使用任何方法来设置操作栏,如下所示:

getSupportActionBar().setHomeButtonEnabled(true);

It will cause a null pointer exception.

它会导致空指针异常。

回答by Rohit Suthar

Try this with appcompat from style.xml. It provides support for all platforms.

用 appcompat 试试这个style.xml。它为所有平台提供支持。

<!-- Application theme. -->
<style name="AppTheme.FullScreen" parent="AppTheme">
    <item name="android:windowFullscreen">true</item>
</style>


<!-- Application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar" />

回答by Filipe Brito

Using Android Studio (current version is 2.2.2 at moment) is very easy to add a fullscreen activity.

使用 Android Studio(当前版本是 2.2.2)很容易添加全屏活动。

See the steps:

查看步骤:

  1. Right click on your java main package > Select “New” > Select “Activity” > Then, click on “Fullscreen Activity”.
  1. 右键单击你的java主包>选择“新建”>选择“活动”>然后,点击“全屏活动”。

Step one

步骤1

  1. Customize the activity (“Activity Name”, “Layout Name” and so on) and click “finish”.
  1. 自定义活动(“活动名称”、“布局名称”等)并单击“完成”。

Step two

第二步

Done!

完毕!

Now you have a fullscreen activity made easily (see the java class and the activity layout to know how the things works)!

现在您可以轻松制作全屏活动(请参阅 java 类和活动布局以了解其工作原理)!

回答by X-Black...

For those using AppCompact... style.xml

对于那些使用 AppCompact... style.xml

 <style name="Xlogo" parent="Theme.AppCompat.DayNight.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
</style>

Then put the name in your manifest...

然后把名字放在你的清单中......

回答by Rajesh Peram

First you must to set you app theme with "NoActionBar" like below

首先,您必须使用“NoActionBar”设置您的应用主题,如下所示

<!-- Application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar" />

Then add these lines in your fullscreen activity.

然后在您的全屏活动中添加这些行。

public class MainActiviy extends AppCompatActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                                  WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
    }
}

It will hide actionbar/toolbar and also statusbar in your fullscreen activity

它将在您的全屏活动中隐藏操作栏/工具栏和状态栏