2

edittext covered by keyboard

Here is my dialog layout content. When the button on the screen clicked, this dialog will be shown, and covered by the keyboard. How to solve this problem ?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="#FFFFFF"
android:layout_width="400dp"
android:layout_height="match_parent">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

    <EditText
        android:layout_width="30dp"
        android:layout_alignParentBottom="true"
        android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
terrrrrrgl
  • 31
  • 5

4 Answers4

2
<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:background="#FFFFFF"
    android:layout_width="400dp"
    android:windowSoftInputMode="adjustPan|adjustResize"
    android:layout_height="match_parent">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

        <EditText
            android:layout_width="30dp"
            android:layout_alignParentBottom="true"
            android:layout_height="wrap_content" />
    </RelativeLayout>
    </LinearLayout>
bhaskar kurzekar
  • 238
  • 2
  • 14
0

Add this to your class:

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

The above line of code will push your layout up to make the EditText visible when it has focus & keyboard is seen.

Aishwarya Tiwari
  • 625
  • 4
  • 19
0

In my case, add a new style can solve this problem

  1. Step1:Add style
<style name="BottomSheetStyle" parent="Theme.Design.Light.BottomSheetDialog">
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowSoftInputMode">adjustResize</item>
</style>
  1. Step 2:Use the style
// method 1
BottomSheetDialog dialog = new BottomSheetDialog(context, R.style.BottomSheetStyle);
// or method 2 
super(context, R.style.BottomSheetStyle);
djzhao
  • 934
  • 10
  • 9
-2

try this

 public void show_Messgae() {

    final Dialog mDialog = new Dialog(this);
    mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    Window window = mDialog.getWindow();
    window.setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    window.setGravity(Gravity.CENTER);
    mDialog.getWindow().setBackgroundDrawable(
            new ColorDrawable(android.graphics.Color.WHITE));

  //diaog is the name of ur layout
    mDialog.setContentView(R.layout.dialog);

    mDialog.setCancelable(false);

    EditText et_name=(EditText)mDialog.findViewById(R.id.et_name);

    //to show keyboard
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);

    mDialog.show();



}
sunil
  • 796
  • 1
  • 8
  • 28