android - 我无法摆脱我的 Android 应用程序中的标题栏

标签 android android-layout android-titlebar

我尝试了几种不同的修复方法来去除我应用中的 TitleBar。

enter image description here

我能够摆脱 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 文件中的 MainActivity Activity 类

android:theme="@style/AppTheme.NoActionBar"

关于android - 我无法摆脱我的 Android 应用程序中的标题栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47625923/

相关文章:

android - 导出的 apk 出错 - FacebookSDK

java - 控制 ime_action_done 行为

android - 外部化字符串是否需要位于 strings.xml 中?

Android 从操作栏中删除标题栏

Android 2.1 : Grateful for crash analysis help: signal 11 (SIGSEGV), 故障地址 deadbaad

android - 通知设置 channel 和 FCM subscribeToTopic 有什么不同?

Android - 约束布局 - 如何将 View 居中对齐到其他 View 的边缘?

android - 如何更改android中的应用程序名称

android - 在 fragment 中隐藏状态栏

Android:ProgressDialog 失败,版本 2