我目前有一个带有工具栏的片段,该工具栏在向下滚动时“消失”,而在向上滚动时“重新出现”,但是我想对其进行更改,以使工具栏的背景在显示时是透明的,而不是一直显示在顶部(甚至只是始终透明)。这是我目前拥有的:
activity_fragment.xml:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="@color/colorPrimaryDark">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="50dp"
app:layout_scrollFlags="scroll|enterAlways"
app:theme="@style/CustomActionBar" />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout >
我在工具栏和AppBarLayout上都尝试过android:background="@null"
,但是没有用。
我怀疑问题出在如何/在哪里fragment_container
下显示的recylerview:
FragmentAlbumGallery.java:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_recycler_gallery, container, false);
mAlbumRecyclerView = (RecyclerView) v.findViewById(R.id.recycler_view);
mAlbumRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
return v;
}
fragment_recycler_gallery.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ActivityGallery"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
答案 0 :(得分:0)
您需要自定义样式 CustomActionBar :
<style name="CustomActionBar">
<item name="android:background">@android:color/transparent</item>
</style>
就这样,伙计们