Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide toolbar in android?

I'm really new on android and working on a small project using one of the google templates; the tabbed activity with tabs...is there a way to hide the title section (tabbedExample) and keep only the tabs?

enter image description here

styles.xml

  <resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

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

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

Manifiest.xml

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

    <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="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>
like image 869
Pedro Avatar asked Nov 16 '18 17:11

Pedro


People also ask

How do I hide the tool bar on my android?

Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.

How do I hide the app bar?

If you want to hide Action Bar from the entire application (from all Activities and fragments), then you can use this method. Just go to res -> values -> styles. xml and change the base application to “Theme. AppCompat.

How do I hide the bottom bar on my Android device?

If you have an Android 4.4 device or higher you can hide the bottom bar (known as the Navigation or System Bar) using the full screen setting - Settings > Display > Full Screen Mode, which is known as immersive mode (image 1 below).

How do I hide the toolbar in an activity?

You can simply hide the toolbar putting this in your activity, into the oncreate method getSupportActionBar ().hide ();

How do I hide the status bar in my App?

You can do this programmatically or by setting an activity theme in your app's manifest file. Setting an activity theme in your app's manifest file is the preferred approach if the status bar should always remain hidden in your app (though strictly speaking, you could programmatically override the theme if you wanted to).

How to hide the toolbar from a fragment?

You can hide toolbar from your fragment like below. override fun onResume () { super.onResume () (activity as AppCompatActivity?)!!.supportActionBar!!.hide () } And don't forget to call show () inside the onStop () in the same fragment' to show the toolbar to other fragment or activity`.


4 Answers

You can simply hide the toolbar putting this in your activity, into the oncreate method:

getSupportActionBar().hide();
like image 149
Gabriele Puia Avatar answered Oct 07 '22 12:10

Gabriele Puia


For Activity:

getSupportActionBar().hide();

For Fragment in Java:

((MainActivity) requireActivity()).getSupportActionBar().hide();

For Fragment in kotlin:

(requireActivity() as MainActivity).supportActionBar!!.hide()
like image 38
Biplob Das Avatar answered Oct 07 '22 13:10

Biplob Das


Instead of this:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

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

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

Write like this:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>
like image 7
Ümañg ßürmån Avatar answered Oct 07 '22 13:10

Ümañg ßürmån


set this theme in your styles.xml file:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
like image 4
Shivam Dawar Avatar answered Oct 07 '22 12:10

Shivam Dawar