我已经尝试了几种不同的修复方法来摆脱我的应用程序中的TitleBar。
我能够摆脱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>
答案 0 :(得分:1)
在样式文件夹中添加此样式
<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
活动类
android:theme="@style/AppTheme.NoActionBar"