rm -rf
rm -rf

Reputation: 1046

remove toolbar in fragment

I used Androids "Bottom Navigation Activity"-example but in every fragment, I have a blank toolbar at the top of the fragment (white bar at the top of the screen in screenshot). I already applied NoActionBar in the Manifest file and also in the layout preview, I can't see a Toolbar. How can I remove the toolbar at the top of each fragment?

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>

enter image description here

Upvotes: 2

Views: 1596

Answers (5)

lookub
lookub

Reputation: 56

Try this :

İf you use java ; write in fragment onCreate:

 GetActivity.getSupportedActionBar.hide();

Or ,

    // set Windows Flags to Full Screen
 getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 

    

Or if you use kotlin ; write in onCreateview:

(activity as AppCompatActivity).supportActionBar!!.hide()}

Or

 requiredActivity.supportActionBar!!.hide()

Upvotes: 4

rm -rf
rm -rf

Reputation: 1046

In activity_main.xml remove android:paddingTop="?actionBarSize" and that will fix the error

Upvotes: 2

ahmad bajwa
ahmad bajwa

Reputation: 1068

You have to add these windowActionBar and windowNoTitle

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
   </style>

Upvotes: 0

Zain
Zain

Reputation: 40858

This is a default behavior for Theme.MaterialComponents.DayNight.NoActionBar Material design dark Theme. Check this answer for more info

If you still want to use this DayNight theme, then you have to remove item name="colorPrimary" attribute and use item name="colorSurface" instead.

Or you can use Theme.MaterialComponents.NoActionBar theme if you don't need Dark mode effect.

Upvotes: 1

Ayush
Ayush

Reputation: 160

Can you try adding below in Theme.Quizeule ?

<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>

Upvotes: 1

Related Questions