我有一种奇怪的情况,我似乎无法弄清楚,我有预感它涉及CollapsingToolbarLayout
。
我有一个包含以下XML布局的活动:
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout>
<android.support.design.widget.CollapsingToolbarLayout
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
app:layout_behavior="@string/appbar_scrolling_view_behavior" >
<android.support.design.widget.TabLayout />
<!-- Two fragments inside ViewPager each containing a RecyclerView -->
<android.support.v4.view.ViewPager />
</LinearLayout>
<!-- User Clicks a button and fragment is added to this framelayout -->
<!-- This fragment overlays on top of the entire Activity layout -->
<!-- This fragment also contains a recyclerview -->
<FrameLayout/>
</android.support.design.widget.CoordinatorLayout>
Activity
的工具栏如下所示:Fragment
的布局上打开Activity
时,会发生这种情况:这是片段的XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:elevation="4dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/fragmentToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
/>
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
这就是我初始化Fragment
工具栏的方式:
private void initToolBar(View root) {
Toolbar toolbar = (Toolbar) root.findViewById(R.id.fragmentToolbar);
toolbar.setBackgroundColor(mColor);
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
((AppCompatActivity) getActivity()).getSupportActionBar().setHomeButtonEnabled(true);
((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(mTitle);
}
答案 0 :(得分:0)
hitch.united指出它就像检查mColor
的值一样简单。浪费了这么多时间!希望这可以帮助其他人,如果他们处于相同的位置!