Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove shadow from status bar android

I've used the following in my style to make the status bar transparent:

<style name="TransparentStatusBar" parent="ThemeBase">
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
</style>

But now there's a shadow at the top of the screen where the status bar was:

img

How can I remove this shadow?

Edit:

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/primary"
    app:layout_scrollFlags="scroll|enterAlways"
    app:theme="@style/ToolbarTheme"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    />

Activity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(getLayoutResource());

    toolbar = (Toolbar) findViewById(R.id.toolbar);

    if (toolbar != null) {
        setSupportActionBar(toolbar);
        toolbar.setNavigationIcon(ContextCompat.getDrawable(this, R.drawable.ic_action_back));
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }
}

ToolbarTheme:

<style name="ToolbarTheme" parent="ThemeBase">
    <item name="android:textColorPrimary">@color/white</item>
</style>
like image 378
user5361880 Avatar asked Dec 24 '22 14:12

user5361880


1 Answers

Late to the party! This black shadow is mainly due to

<item name="android:windowTranslucentStatus">true</item>

There are two ways you can handle that.

  1. You only need to have the same color for status bar as the below view.

    (This way is if you add a background image you gets caught.Because actually its two views,Status bar and its below View in same color.Yet some people need this! )

    For this you do not need android:windowTranslucentStatus.It will make that black shadow! Making <item name="android:statusBarColor">@color/asSameColorAsBelowViewColor</item> you can achieve it.Even this can be applied to OP's question here.But its for colors.Other wise you get trapped.


  1. You really need to go your view behind StatusBarwithout that black shadow.

    eg: In a situation that you need to use an image.

    For this again if you are using <item name="android:windowTranslucentStatus">true</item> you can remove it and add <item name="android:statusBarColor">@color/transparent</item>

    and add getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); in your Activity before setContentView().

like image 168
Charuක Avatar answered Jan 13 '23 22:01

Charuක