我有一個collapsingToolbarLayout
,我需要對標題TextView
做一些額外的設置。獲取摺疊工具欄佈局的標題textview
問題:如何獲得對該TextView的引用?
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/review_coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.stack.overflow.reviewmaschine.ReviewMaschineActivity"
tools:ignore="MergeRootFrame">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="@+id/toolbar">
<android.support.v7.widget.Toolbar
android:id="@+id/detail_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/item_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior = "@string/appbar_scrolling_view_behavior"
/>
<com.mego.smscloud.reviewmaschine.SaveFloatingActionButton
android:id="@+id/review_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:backgroundTint="@color/colorPrimary"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_floppy_white_48dp"
app:borderWidth="0dp"
app:elevation="@dimen/fab_elevation"
app:rippleColor="#00ffff"/>
</android.support.design.widget.CoordinatorLayout>
編輯: 簡單地增加一個TextView
到Toolbar
不作爲CollapsingToolbarLayout
標題確實
我已將您的答案作爲解決方案進行檢查,因爲它會爲我返回正確的textview。不幸的是,我不能設置任何東西到textview。請參閱我的代碼:protected void onResume(){ mTitleTextView =(TextView)getTitleTextView(mToolbar); if(mTitleTextView!= null){mtitleTextView.setText(「BLJSDosdjif」); } super.onResume(); } – jublikon
嗯,'CollapsingToolbarLayout'將會在'Toolbar'上設置一些東西,就像標題一樣。如果您在'super.onResume()'調用後移動它,那麼該代碼可能會工作。稍後當我有機會時,我會看看'CollapsingToolbarLayout'的源代碼,但我還沒有使用它,所以我不確定它是如何處理的。 –
我試圖在super.onResume()之後運行代碼。不幸的是它仍然不起作用。如果你有一點點看,我將非常感激。提前謝謝 – jublikon