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
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
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
<?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
<?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>
It looks that editing your Manifest and adding
android:windowSoftInputMode="adjustResize"
to<activity>
tag of this activity should solve your problem.Docs: https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
Using this KeyboardUtil as new solution !
Use this in onCreateDialog in BottomSheetFragment
or
For fragment use
by using this Util class
https://github.com/mikepenz/MaterialDrawer/blob/aa9136fb4f5b3a80460fe5f47213985026d20c88/library/src/main/java/com/mikepenz/materialdrawer/util/KeyboardUtil.java
Credit:Mikepenz