Reputation: 7799
I can't hide a title in my Toolbar
that I set as ActionBar
.
Here my activity style:
<style name="Theme.Paper" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="windowActionModeOverlay">true</item>
</style>
Layout:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<!-- some data -->
</data>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Theme.Paper.AppBarOverlay">
<include
android:id="@+id/toolbar_layout"
layout="@layout/toolbar_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
</layout>
And Toolbar
layout:
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/Theme.Paper.Toolbar.PopupOverlay"
app:theme="@style/Theme.Paper.Spinner.PopupOverlay">
<Spinner
android:id="@+id/toolbar_spinner"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:popupTheme="@style/Theme.Paper.Spinner.PopupOverlay"/>
</android.support.v7.widget.Toolbar>
</layout>
Here a code is in the onCreate
method:
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_editor);
//Set ToolBar
setSupportActionBar(mBinding.toolbarLayout.toolbar);
//Up navigation
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false); // Try to hide a title
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(VectorDrawable
.getDrawable(this, R.drawable.ic_close_white_24dp));
}
But it doesn't work, a title still shows.
Where can a problem be?
ADDED
This is my debug screen:
As you can see my ActionBar
is not null.
Upvotes: 1
Views: 1139
Reputation: 23881
As you are using toolbar you can use:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("");
Upvotes: 2