1

For my app in the main tasks i take quite a bit of input from the user. Currently when they go to enter their input the keyboard rises and the bottom navigation view stays visible above it. However what i want to happen is that when the keyboard pops up the bottom nav should go away and not be visible to the user.So i do i do this?

Code for MainActivity which contains the bottom nav bar.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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.support.v7.widget.Toolbar
        android:id="@+id/maintoolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_below="@id/maintoolbar"
        android:layout_above="@+id/bottom_navigation"/>

    <android.support.design.widget.BottomNavigationView     
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_alignParentBottom="true"
        android:background="@color/colorPrimary"
        app:itemIconTint="@color/white"
        app:itemTextColor="@color/white"
        app:elevation="4dp"
        app:menu="@menu/bottom_navigation_main"/>

</RelativeLayout>

I want the transition to be as quick and clean as possible so the user can barely notice the change.

euandeas
  • 87
  • 1
  • 9

2 Answers2

3

Add this in the activity tag for MainActivity in your AndroidManifest.xml file:

android:windowSoftInputMode="adjustPan"

EDIT: workaround if above solution doesn't work: Add Focus change listener on each of your edittext. If it receives focus, then the keyboard will show up. So hide your bottomview.

View.OnFocusChangeListener myFocusListener = new OnFocusChangeListener() {
    @Override
    public void onFocusChange(View view, boolean hasFocus) {
        if (hasFocus) {
            bottomNavigationView.setVisiblity(View.GONE);
        } else {

            bottomNavigationView.setVisiblity(View.VISIBLE);

        }
    }
};

editText1.setOnFocusChangeListener(myFocusListener);
editText2.setOnFocusChangeListener(myFocusListener);
...
nupadhyaya
  • 1,909
  • 1
  • 14
  • 14
-1

You can try to add WindowSoftInputMode=SoftInput.AdjustPan at the top of your Activity like this:

[Activity(WindowSoftInputMode=SoftInput.AdjustPan)]

Another option is to add a ViewSourceObserver to the keyboard and hide the BottomNavigationView when the keyboard appears, then show the BottomNavigationView when the keyboard is gone. The first option is probably better though.

Dennis Reep
  • 97
  • 2
  • 9