android - 不在顶部时将工具栏设置为透明?
问题描述
我目前有一个带有工具栏的片段,该片段在向下滚动时“消失”并在向上滚动时“重新出现”,但我想更改它,以便工具栏的背景在显示时是透明的,而不是一直在顶部(或甚至总是透明的)。这是我目前拥有的:
活动片段.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 >
我在 Toolbar 和 AppBarLayout 上都试过android:background="@null"
了,但是没有用。
我怀疑问题出在我如何/在哪里膨胀显示在下面的recylerview fragment_container
:
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>
解决方案
您需要自定义样式CustomActionBar:
<style name="CustomActionBar">
<item name="android:background">@android:color/transparent</item>
</style>
就是这样,伙计们
推荐阅读
- firebase - Firebase 登录和使用 Apple 登录未链接到同一用户帐户
- async-await - 如何在 @click 使用 Vue3 调用的异步函数中清空数组
- php - 未找到 Laravel 5.0 类
- next.js - 下一个 JS -
- prometheus-alertmanager - Alertmanager 将聚合/合并警报发送到 Webhook
- google-cloud-bigtable - CBT 导出 BigTable 数据
- laravel - 我在 laravel 中使用授权。为什么返回 true checkPermissionAccess 函数
- algorithm - 找到范围 [l,r] 中值 a[x]>u 的第一个索引 x
- node.js - 自定义源/来自 modemailer 和 aws SES
- html - 该按钮未按我希望的那样显示