为了设置一张图片作为背景,要将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透明当然是必要的。