24

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>
Pedro
  • 1,440
  • 2
  • 15
  • 36

7 Answers7

28

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

getSupportActionBar().hide();
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Gabriele Puia
  • 333
  • 1
  • 3
  • 10
  • weird that `actionBar.hide()` doesn't work even though it's a method – lasec0203 May 31 '20 at 20:49
  • that's because actionBar is not the same as supportActionBar, they are two different implementations inside Android SDK. the old one is actionBar, and the support library added supportActionBar besides all the other compatibility implementations for older Android Versions. – Jonathan Aste Jun 12 '20 at 15:22
15

For Activity:

getSupportActionBar().hide();

For Fragment in Java:

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

For Fragment in kotlin:

(requireActivity() as MainActivity).supportActionBar!!.hide()
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Biplob Das
  • 2,818
  • 21
  • 13
7

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>
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Ümañg ßürmån
  • 9,695
  • 4
  • 24
  • 41
4

set this theme in your styles.xml file:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
Ümañg ßürmån
  • 9,695
  • 4
  • 24
  • 41
Shivam Dawar
  • 493
  • 7
  • 6
1

You should try this.requestWindowFeature(Window.FEATURE_NO_TITLE); in your onCreate()

Or even simpler, set your theme to: @android:style/Theme.NoTitleBar

The very similar question was answered here

You should find more answers there.

Sk83r1l4m4
  • 153
  • 11
1

Use this on create method:

getActionBar().hide();
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
0

this helped me

supportActionBar?.hide();