2017-01-29 31 views
0

Ich kann einen Titel in meinem Toolbar nicht verbergen, den ich als ActionBar einstelle. Hier meine Tätigkeit Stil:Die ActionBar versteckt keinen Titel

<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> 

Und 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> 

Hier ist ein Code in der onCreate Methode:

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)); 
} 

Aber es funktioniert nicht, ein Titel zeigt immer noch.
Wo kann ein Problem sein?

ADDED
Das ist mein Debug-Fenster: Screenshot
Wie Sie meine ActionBar sehen kann nicht null ist.

+0

Ich denke, Sie sollten nicht ActionBar erstellen und zuweisen ihn als 'getSupportActionBar();' 'nur getSupportActionBar() aufrufen setDisplayShowTitleEnabled (false);. 'Das funktioniert jedes Mal für mich. – Yupi

+0

Es ist gleich. Aber ich habe diese Version auch schon überprüft. Es funktioniert nicht. –

Antwort

1

Wie Sie Toolbar verwenden, können Sie verwenden:

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

Danke! Ich weiß, dass ich einfach einen leeren Text setzen kann. Aber ich möchte verstehen, warum eine normale Variante nicht funktioniert. –

+0

Sie verwenden das Thema 'NoActionBar', so dass Ihre' ActionBar actionBar = getSupportActionBar() '; ... Null gibt – rafsanahmad007

+0

Nein, Sie haben nicht Recht) –

Verwandte Themen