How to set ActionBar for transaparent and keep it over ImageView

大城市里の小女人 提交于 2020-12-02 00:23:04

问题


I want to make the ActionBar transparent and it above the image like this picture. How set it?

enter image description here


回答1:


Layout

<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>

Solution 1#

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

Solution 2#

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



回答2:


@maros136:

I think you should add the toolbar layout below the framelayout_content and the root layout should be a RelativeLayout in order to have the toolbar always on top.

Like this:

<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>

Result:

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



来源:https://stackoverflow.com/questions/30916663/how-to-set-actionbar-for-transaparent-and-keep-it-over-imageview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!