简体   繁体   中英

Unnecessary view on top of CoordinatorLayout

View Hierarchy

<LinearLayout>
<Toolbar>..
</Toolbar>
<FrameLayout>
<CoordinatorLayout>..
<FrameLayout>
</FrameLayout>
</CoordinatorLayout>
</FrameLayout>
</LinearLayout>

在此处输入图片说明

Want to get rid of that dark blue strip . Not sure why Co-ordinatorLayout is appending this view on the top. I tried replacing it with LinearLayout which led to desired results. Not able to figure out why and what view is being displayed as the blue dark strip.

toolbar_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_marginTop="20dp"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@color/white"
        app:title="DISCOVER"
        app:titleTextAppearance="@style/TextAppearance.MyApp.Widget.ActionBar.Title" />

    <View
        style="@style/Divider"
        android:background="@color/grey_light" />

    <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white">

    </FrameLayout>

</LinearLayout>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.discover.MainActivity">

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.discover.MainActivity"
    tools:showIn="@layout/activity_main"
    android:layout_margin="0dp"
    android:background="#11a2cb"></FrameLayout>

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

BaseActivity.java

@Override
    public void setContentView(int layoutResID) {
        super.setContentView(R.layout.toolbar_layout);
        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        mContentlayout = (FrameLayout) findViewById(R.id.content);
        setSupportActionBar(mToolbar);
        getLayoutInflater().inflate(layoutResID, mContentlayout);
    }

In MainActivity I am using setContentView(R.layout.activity_main)

Solution:

Adding android:fitsSystemWindows="true" to the root layout ie LinearLayout in my case worked like a charm.

Cause:

I am still wondering what mysterious view was being displayed. If anybody could point out, please do respond for understanding the issue more clearly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM