Android软键盘在底表的recyclerview中覆盖edittext [英] android soft keyboard overlays the edittext in recyclerview in bottomsheet

查看:663
本文介绍了Android软键盘在底表的recyclerview中覆盖edittext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在BottomSheetDialog内的RecyclerView中有一些EditText.我现在遇到的问题是,当屏幕上显示BottomSheetDialog时,我点击了RecyclerView中的第7个EditText.软键盘出现并覆盖在EditText上,因此我看不到键入的内容.但是如果我将BottomSheetDialog稍微向上拖动,即使我点击屏幕上的最后一个EditTextEditText也不会被软键盘覆盖.在这种情况下,RecyclerView的大小肯定会调整,但如果我不稍稍拖动BottonSheetDialog,则不会调整大小.知道为什么吗?以及我该如何解决?

I have a few EditText in RecyclerView that is inside of a BottomSheetDialog. The problem I have now is that when BottomSheetDialog is shown on the screen, I tap on for example the 7th EditText in the RecyclerView. Soft keyboard appears and overlays the EditText, so I can't see what I type. but if I dragged the BottomSheetDialog a bit up, EditText then won't be covered by soft keyboard even if I tap on last EditText on the screen. RecyclerView is definitely resized in this case but doesn't resize if I didn't drag BottonSheetDialog a bit up. any idea why? and how I can fix this?

这是它的样子.

Main.java

Main.java

class VH extends RecyclerView.ViewHolder {
    public VH(View itemView) {
        super(itemView);
    }
}

private void test() {
    BSTest bsTest = new BSTest(this);
    bsTest.setContentView(R.layout.bottomsheet_test);
    RecyclerView rv = (RecyclerView) bsTest.findViewById(R.id.recyclerView);
    rv.setLayoutManager(new LinearLayoutManager(this));
    rv.setAdapter(new RecyclerView.Adapter() {
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return new VH(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_edittext, parent, false));
        }

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        }

        @Override
        public int getItemCount() {
            return 20;
        }
    });
    bsTest.show();
}

BSTest.java

BSTest.java

public class BSTest extends BottomSheetDialog {
    public BSTest(@NonNull Context context) {
        super(context);
    }

    private BSTest(@NonNull Context context, @StyleRes int theme) {
        super(context, theme);
    }

    private BSTest(@NonNull Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }
}

bottomsheet_test.xml

bottomsheet_test.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="1"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="2"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="3"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

item_edittext.xml

item_edittext.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="1"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="2"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="3"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

推荐答案

将此KeyboardUtil用作新解决方案!

Using this KeyboardUtil as new solution !

在BottomSheetFragment的onCreateDialog中使用它

Use this in onCreateDialog in BottomSheetFragment

KeyboardUtil(getActivity(), view);

用于片段使用

new KeyboardUtil(this, findViewById(R.id.fragment_container));

使用此Util类

https://github.com/mikepenz/MaterialDrawer/blob/aa9136fb4f5b3a80460fe5f47213985026d20c88/library/src/main/java/com/mikepenz/materialdrawer/util/KeyboardUtil.java

信用:迈克彭斯

这篇关于Android软键盘在底表的recyclerview中覆盖edittext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆