在我的MainActivity中,我有一個CollapsingToolbarLayout
。默認情況下,它展開的工具欄。但我想讓它崩潰。因此,作爲在StackOverflow的問題,建議我用AppBarLayout
類,使其坍塌在默認情況下,使用此代碼:當CollapsingToolbarLayout崩潰時,工具欄標題不顯示
AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.app_bar_layout);
appBarLayout.setExpanded(false);
這工作得很好,除了一兩件事。工具欄標題不再顯示,即使我手動展開和摺疊工具欄。如果默認情況下我不折疊工具欄,則會顯示標題,但是如果我從CollapsingToolbarLayout
更改imageView
,那麼標題會消失。
這裏是我的CollapsingToolbarLayout
代碼:
ViewCompat.setTransitionName(findViewById(R.id.app_bar_layout), EXTRA_IMAGE);
CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
collapsingToolbarLayout.setTitle("Search Activity");
collapsingToolbarLayout.setExpandedTitleColor(getResources().getColor(android.R.color.transparent));
collapsingToolbarLayout.setCollapsedTitleGravity(Gravity.START);
我的問題是:我是不正確設置標題還是我沒有在正確的道路塌陷工具欄?我怎樣才能解決這個問題?
謝謝你的幫助!
支持庫的版本,您使用哪個?這聽起來像CollapsingToolbarLayout前一段時間的bug ... –
@BartekLipinski最後一個版本。我的app build.gradle說:'compile'com.android.support:cardview-v7:24.2.0'' compile'com.android.support:recyclerview -v7:24.2.0'' compile'com.android。 support:design:24.2.0''' compile'com.android.support:appcompat-v7:24.2.0'' –