Entfernen Sie die Symbolleiste im Fragment
Ich habe Androids "Bottom Navigation Activity" -Beispiel verwendet, aber in jedem Fragment habe ich eine leere Symbolleiste am oberen Rand des Fragments (weiße Leiste am oberen Bildschirmrand im Screenshot). Ich habe NoActionBar bereits in der Manifest-Datei angewendet und auch in der Layoutvorschau kann ich keine Symbolleiste sehen. Wie kann ich die Symbolleiste oben in jedem Fragment entfernen?
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.myapp.test">
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Quizeule">
<activity android:name=".activities.PlayActivity" />
<activity android:name=".activities.SplashScreenActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activities.LoginActivity" />
<activity android:name=".MainActivity" />
</application>
</manifest>
Themes.xml:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Quizeule" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>

Antworten
In activity_main.xml
entfernen android:paddingTop="?actionBarSize"
und das wird den Fehler beheben
Können Sie versuchen, unten in Theme.Quizeule hinzuzufügen?
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
Dies ist ein Standardverhalten für das Theme.MaterialComponents.DayNight.NoActionBar
dunkle Design des Materialdesigns. Überprüfen Sie diese Antwort für weitere Informationen
Wenn Sie dieses DayNight-Thema weiterhin verwenden möchten, müssen Sie das item name="colorPrimary"
Attribut entfernen und item name="colorSurface"
stattdessen verwenden.
Oder Sie können ein Theme.MaterialComponents.NoActionBar
Thema verwenden, wenn Sie keinen Dunkelmodus-Effekt benötigen.
Sie müssen diese windowActionBar
und hinzufügenwindowNoTitle
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Versuche dies :
Wenn Sie Java verwenden; schreibe in Fragment onCreate:
GetActivity.getSupportedActionBar.hide();
Oder ,
// set Windows Flags to Full Screen
getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Oder wenn Sie Kotlin verwenden; Schreiben Sie in onCreateview:
(activity as AppCompatActivity).supportActionBar!!.hide()}
Oder
requiredActivity.supportActionBar!!.hide()