如何为透明设置 ActionBar 并将其保留在 ImageView 上

How to set ActionBar for transaparent and keep it over ImageView

我想让 ActionBar 透明,并且像这张图一样放在图片上方。 怎么设置?

布局

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/background_white"
    android:minHeight="?attr/actionBarSize" />

    <FrameLayout
        android:id="@+id/framelayout_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</FrameLayout>

解决方案 1#

//whole toolbar will be transparent 
mToolbar.setAlpha(0.0f);

解决方案 2#

//only background of toolbar will be transparent 
mToolbar.getBackground().setAlpha(0);

@maros136:

我认为您应该在 framelayout_content 下面添加工具栏布局,并且根布局应该是 RelativeLayout 以使工具栏始终位于顶部。

像这样:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/main_details_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        Your layout here
    </LinearLayout>

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/transparent"
        />

</RelativeLayout>

结果:

https://play.google.com/store/apps/details?id=com.levionsoftware.photos