我无法摆脱 Android 应用中的 TitleBar

I can't get rid of the TitleBar in my Android app

我尝试了几种不同的修复方法来去除我的应用程序中的标题栏。

我能够摆脱 MainActivity 中最顶部的栏(包括时间、电池等),但 TitleBar 不会消失。这是我用来使顶部栏消失的代码:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);

这是我的 activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background_flat_720x1280"
    tools:context="com.andrewvanpeter.upandaway.MainActivity">

    <Button
        android:id="@+id/settingsButton"
        android:layout_width="128dp"
        android:layout_height="38dp"
        ...
</android.support.constraint.ConstraintLayout>

这是我的 AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.andrewvanpeter.upandaway">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".GameActivity" />
        <activity android:name=".HelpActivity" />
        <activity android:name=".SettingsActivity" />
    </application>
</manifest>

将此样式添加到您的样式文件夹中

    <style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.DarkActionBar"> 
<item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> 
<item name="android:windowFullscreen">true</item> 
</style>

在您的AndroidManifest.xml文件

中将此样式设置为您的MainActivityactivityclass
android:theme="@style/AppTheme.NoActionBar"