Transparent action bar not being fully transparent. (Leaves weirdbox)

橙三吉。 提交于 2019-12-12 02:35:58

问题


I've tried setting the action bar I custom-made for my application to be transparent. However instead of being completely transparent, it leaves a weird elevation shadow:

http://puu.sh/rdYyb/04ce0147f6.jpg

The XML for the bar:

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbarlayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

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

</android.support.design.widget.AppBarLayout>


<android.support.design.widget.FloatingActionButton
    android:id="@+id/OverviewFAB"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/ic_add_alert" />

<RelativeLayout
    android:id="@+id/main_fragment_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

The styles XML for my themes:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"></style>

How I programatically try to remove the elevation and background in the activity:

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appbarlayout);
    appBarLayout.setElevation(0);
    toolbar.setElevation(0);
    appBarLayout.setBackgroundColor(ContextCompat.getColor(this, android.R.color.transparent));
    toolbar.setBackgroundColor(ContextCompat.getColor(this, android.R.color.transparent));

But despite all this the box (shown in the link) still persists... I'm not sure what's going on? Does anyone see anything wrong in my code?


回答1:


try putting inside app bar

app:elevation="0dp"

this inside your toolbar

android:background="@android:color/transparent"



回答2:


I think you need to use "android:alpha="0.5" or use setAlpha() method.




回答3:


i tried this and its worked for me and add this four line into toolbar widget in xml file.

app:contentInsetEnd="0dp"
            app:contentInsetLeft="0dp"
            app:contentInsetRight="0dp"
            app:contentInsetStart="0dp"


来源:https://stackoverflow.com/questions/39543177/transparent-action-bar-not-being-fully-transparent-leaves-weirdbox

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