Skip to content

A big gap above an ActionBar on Android 5+ #61

Closed
Neustart opened this Issue · 9 comments

3 participants

@Neustart

I using the latest version of library, but every time when I launch app on device with android 5+ I have a gap like on screen:
http://snag.gy/ugDqX.jpg
On device with Android 4.4 everything is fine:
http://snag.gy/yDSf3.jpg

@roughike
Owner

Could you provide a sample of your XML layout and your Java code for attaching the BottomBar to your layout?

@grocaDW

I have the same issue. Here is an snippet.

activity_layout.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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/bg_light_grey">

    <include layout="@layout/toolbar"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

    </RelativeLayout>

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

toolbar.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
    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="wrap_content"
    android:fitsSystemWindows="true">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:layout_scrollFlags="scroll|enterAlways"
        android:background="@color/primary"
        android:theme="@style/AppTheme.ActionBar"/>

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

MainActivity.java

...
    private BottomBar mBottomBar;

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getActivityComponent().inject(this);
        setContentView(R.layout.activity_layout);
        ButterKnife.bind(this);
        setupToolbar();
        setupBottomBar(savedInstanceState);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);

        // Necessary to restore the BottomBar's state, otherwise we would
        // lose the current tab on orientation change.
        mBottomBar.onSaveInstanceState(outState);
    }

    private void setupToolbar() {
        setSupportActionBar(mToolbar);
    }

    private void setupBottomBar(Bundle savedInstanceState) {
        mBottomBar = BottomBar.attach(this, savedInstanceState);
        mBottomBar.setItemsFromMenu(R.menu.bottombar, new OnMenuTabSelectedListener() {
            @Override
            public void onMenuItemSelected(int resId) {
                if (resId == R.id.bottomBarHome) {
                    // the user selected item number one
                }
            }
        });

        // Setting colors for different tabs when there's more than three of them.
        // You can set colors for tabs in three different ways as shown below.
        mBottomBar.mapColorForTab(0, ContextCompat.getColor(this, R.color.accent));
        mBottomBar.mapColorForTab(1, 0xFF5D4037);
        mBottomBar.mapColorForTab(2, "#7B1FA2");
        mBottomBar.mapColorForTab(3, "#FF5252");
    }

BTW, thanks of this awesome library. :)

Looking forward for new updates.

EDIT: With mBottomBar.noTopOffset(); doesn't work either, there is an overlap of the toolbar and the statusbar.

@roughike
Owner

@grogaDW

Try attaching it to your fragment container.

mBottomBar.attach(findViewById(R.id.fragmentContainer), savedInstanceState);
@grocaDW

@roughike Nope, now it overlaps not only the statusbar (the toolbar) but the navigation bar as well (the bottombar). BTW, I'm testing in a Moto G 3rd Gen 6.0

@grocaDW

Great! I made it to work just adding:
mBottomBar.useOnlyStatusBarTopOffset();
And I didn't have to change; android:fitsSystemWindows="true"
Thanks!

@roughike
Owner

@grocaDW Nice!

@grocaDW

I found a new issue but I think is related. It doesn't work if we attach a recycleview. The toolbar doesn't completely disappear when we scroll, just the top half of it if mBottomBar.useOnlyStatusBarTopOffset(); is enabled.

On the other side if we use mBottomBar.noTopOffset(); it only shows the bottom half of the Toolbar without scroll. In this case when we scroll all the toolbar is correctly hided.

Thanks

@Neustart

@grocaDW mBottomBar.useOnlyStatusBarTopOffset(); works for me too ! Great, thank you

@roughike
Owner

That's awesome!

@roughike roughike closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.