我如何使一个活动全屏?没有通知栏。


当前回答

小心

requestWindowFeature(Window.FEATURE_NO_TITLE);

如果您正在使用任何方法设置操作栏如下:

getSupportActionBar().setHomeButtonEnabled(true);

它将导致一个空指针异常。

其他回答

在Android 10上,没有一款适合我。

但我工作得很好(oncreate的第一行):

    View decorView = getWindow().getDecorView();
    int uiOptions = View.SYSTEM_UI_FLAG_IMMERSIVE;
    decorView.setSystemUiVisibility(uiOptions);

    setContentView(....);

    if (getSupportActionBar() != null) {
        getSupportActionBar().hide();
    }

享受:)

对于那些使用AppCompact的人… style.xml

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

那就把名字写在你的载货单上…

主题

    <style name="Theme.FluidWallpaper.FullScreen" parent="@style/Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:navigationBarColor">@android:color/transparent</item>
    <item name="android:windowLayoutInDisplayCutoutMode" tools:targetApi="o_mr1">shortEdges</item>
     </style>

安卓清单

   <activity android:exported="false"
        android:name=".FullScreenActivity"
        android:screenOrientation="fullSensor"
        android:theme="@style/Theme.FluidWallpaper.FullScreen"/>

在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>  

或者在Java代码中:

protected void onCreate(Bundle savedInstanceState){
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
 protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_splash_screen);
    getSupportActionBar().hide();

}