Подтвердить что ты не робот

Как скрыть BottomNavigationView под клавиатурой с помощью setResize set

Согласно спецификации дизайна материала, когда клавиатура появляется, BottomNavigationView должен скрываться под ней. Однако, если я установил android:windowSoftInputMode="adjustResize" в манифесте Activity, то BottomNavigationView перемещается над клавиатурой.

Мне нужно установить adjustResize чтобы включить прокрутку в нижней части экрана, пока клавиатура открыта. Тем не менее, я не хочу, чтобы вид BottomNavigationView был видимым. Это можно сделать?

Как это выглядит в настоящее время:

enter image description here

Формат XML (на самом деле там будет FrameLayout где находится EditText, и EditText будет внутри него):

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Input"
        android:layout_gravity="center"
        android:layout_centerVertical="true"/>

    <android.support.design.widget.BottomNavigationView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:itemBackground="@color/colorPrimary"
        app:menu="@menu/menu_bottom_navigation"
        app:itemIconTint="@android:color/white"
        app:itemTextColor="@android:color/white"/>

</RelativeLayout>
4b9b3361

Ответ 1

Добавьте это в свою деятельность в манифест

android:windowSoftInputMode="adjustPan"

Так что

<activity android:name=".feature.home.HomeActivity" 
 android:windowSoftInputMode="adjustPan"/>

Ответ 2

Существует еще одно решение, которое не требует adjustSpan, но оно работает только для API >= 21. Вы можете определить, отображается или скрыта клавиатура, отслеживая системные вставки. Скажем, у вас есть BottomNavigationView, который является дочерним по LinearLayout и вам нужно скрыть его, когда отображается клавиатура:

> LinearLayout
  > ContentView
  > BottomNavigationView

Все, что вам нужно сделать, это расширить LinearLayout таким образом:

public class KeyboardAwareLinearLayout extends LinearLayout {
    public KeyboardAwareLinearLayout(Context context) {
        super(context);
    }

    public KeyboardAwareLinearLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public KeyboardAwareLinearLayout(Context context,
                                     @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public KeyboardAwareLinearLayout(Context context, AttributeSet attrs,
                                     int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    public WindowInsets onApplyWindowInsets(WindowInsets insets) {
        int childCount = getChildCount();
        for (int index = 0; index < childCount; index++) {
            View view = getChildAt(index);
            if (view instanceof BottomNavigationView) {
                int bottom = insets.getSystemWindowInsetBottom();
                if (bottom >= ViewUtils.dpToPx(200)) {
                    view.setVisibility(GONE);
                } else {
                    view.setVisibility(VISIBLE);
                }
            }
        }
        return insets;
    }
}

Идея состоит в том, что при отображении клавиатуры системные вставки изменяются с довольно большим значением .bottom.

Ответ 3

добавьте следующую строку в ваш манифест: android: windowSoftInputMode = "adjustPan"

<activity
   android:name=".main.MainActivity"
   android:screenOrientation="portrait"
   android:windowSoftInputMode="adjustPan" />

Ответ 4

вы просто добавляете этот код в свой манифест таким образом.

 <activity android:name=".MainActivity"
        android:windowSoftInputMode="adjustPan">

это работает для меня.. счастливое кодирование

Ответ 5

Как альтернативный способ с вашим android:windowSoftInputMode="adjustResize" вы можете попробовать это.

вызовите этот метод из своего OnCreate - как только клавиатура встанет, вы можете изменить видимость просмотров, которые вам не нужно показывать! Когда клавиатура выключена, снова отобразите их.

 public void checkKeyBoardUp(){
        rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                Rect r = new Rect();
                rootView.getWindowVisibleDisplayFrame(r);
                int heightDiff = rootView.getRootView().getHeight() - (r.bottom - r.top);

                if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
                    //ok now we know the keyboard is up...
                    whatEverView.setVisibility(View.INVISIBLE);

                }else{
                    //ok now we know the keyboard is down...
                    whatEverView.setVisibility(View.VISIBLE);
              }
            }
        });
    }