简体   繁体   English

Android工具栏不会隐藏标题

[英]Android Toolbar doesn't hide a title

I can't hide a title in my Toolbar that I set as ActionBar . 我无法在设置为ActionBar Toolbar隐藏标题。 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: Toolbar布局:

<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: 这里的代码在onCreate方法中:

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. 如您所见,我的ActionBar不为null。

As you are using toolbar you can use: 使用工具栏时,可以使用:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM