2015-09-25 64 views
15

設置我的工具欄一collapsingtoolbarlayout內,像這樣:工具欄字幕沒有出現

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/detail_backdrop_height" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapsing_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 


     <ImageView 
      android:id="@+id/backdrop" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      app:layout_collapseMode="parallax" /> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/detail_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_collapseMode="pin"/> 


    </android.support.design.widget.CollapsingToolbarLayout> 
</android.support.design.widget.AppBarLayout> 

然而,當我嘗試設置標題和副標題,只有標題顯示在工具欄中!

private void setupToolbar(){ 
    toolbar = (Toolbar) findViewById(R.id.detail_toolbar); 
    if(toolbar != null){ 
     setSupportActionBar(toolbar); 
    } 

    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
    getSupportActionBar().setTitle(mTitle); 
    getSupportActionBar().setSubtitle("Subtitle); 
} 

如何訪問工具欄的副標題?

+0

不確定[http://stackoverflow.com/questions/26517166/android-material-with-extended-toolbar](http://stackoverflow.com/questions/26517166/android-material-with-extended-toolbar ) –

+0

可能[this](http://stackoverflow.com/questions/31194280/collapsingtoolbarlayout-subtitle)答案可以幫助你。 –

+0

有人找到了解決方案嗎? –

回答

-3

嘗試直接引用您的工具欄,而不是嘗試通過getSupportActionBar()設置標題/副標題。因此,與其:

toolbar.setTitle() toolbar.setSubtitle()

標題/副標題應該後適當工作。