设置Toolbar透明

为了设置一张图片作为背景,要将Toolbar设置为透明,为了这个折腾一天了,网上各种教程都试过了就是没用,每次设置Toolbar透明之后,Toolbar都成了白色,怎么也找不到原因,最后最后才发现因为我顶层布局用到是LinearLayout,设置Toolbar透明之后显示的是Activity的底色!啥也不说了把代码贴上来。感谢这篇文章让我找到了原因:http://stackoverflow.com/questions/26452431/transparent-actionbar-with-appcompat-v7-21/27705929#27705929

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false">

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" />

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:background="#00000000"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:fitsSystemWindows="true"/>

</FrameLayout>

说明一下,原作者说第1要保证顶层布局要是RelativeLayout,其实只要不是LinearLayout就行了,第2要让Toolbar放在最后,其实是为了防止Toolbar被其他内容挡住,最后设置toolbar透明当然是必要的。

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值