Skip to content Skip to sidebar Skip to footer

Android Remove Actionbar Title Keeping Toolbar Menu

I need to keep my tabbed toolbar in my application removing the actionbar. This is how it looks like now: But I want it to look like this: My code xml is:

Solution 1:

Simply add this in your MainActivity this will hide the text of your toolbar

getSupportActionBar().setTitle("");

To remove the toolbar you can set it's visibility to gone like

android:visibility="gone"

Solution 2:

Here are your options:

1. It looks like you don't need Toolbar here at all. You can remove it from your xml file and add this line

getSupportActionBar().hide();

to your MyActivity.java instead of

if (toolbar != null) {
    setSupportActionBar(toolbar);
}

2. If you want to keep the Toolbar in case of using it later, you can hide it in either xml file

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:visibility="gone"
    android:background="?attr/colorPrimary"/>

or in your MyActivity.java after setting Toolbar as support action bar

if (toolbar != null) {
    setSupportActionBar(toolbar);
}
toolbar.setVisibility(View.GONE);

Solution 3:

Add following code to disable actionbar and enable toolbar in following files :-

Add this code to styles.xml

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

for custom toolbar create layout/toolbar.xml

<ImageViewandroid:id="@+id/backButton"android:layout_width="48dp"android:layout_height="48dp"android:layout_marginLeft="16dp"android:background="@drawable/back"android:padding="24dp"android:visibility="gone" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:orientation="horizontal"><TextViewandroid:id="@+id/toolbarText"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/app_name"android:textColor="@color/white" /></LinearLayout>

in layout/activity.xml

<include
    android:id="@+id/mallToolbar"
    layout="@layout/toolbar" />

in MainActivity.java Add:-

    toolbar = (Toolbar) findViewById(R.id.mallToolbar);
    setSupportActionBar(toolbar);

Now you have added a custom toolbar to your android activity.

Post a Comment for "Android Remove Actionbar Title Keeping Toolbar Menu"