带有EditText的Android BottomSheetDialog由键盘覆盖

时间:2017-03-22 06:59:48

标签: android android-softkeyboard

edittext covered by keyboard

这是我的对话框布局内容。单击屏幕上的按钮时,将显示此对话框,并由键盘覆盖。如何解决这个问题?

<?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>

4 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

将此添加到您的班级:

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

以上代码行将推动您的布局,使EditText在焦点和焦点时可见;看到键盘。

答案 2 :(得分:0)

就我而言,添加新样式可以解决此问题

  1. 第一步:添加样式
<style name="BottomSheetStyle" parent="Theme.Design.Light.BottomSheetDialog">
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowSoftInputMode">adjustResize</item>
</style>
  1. 第2步:使用样式
// method 1
BottomSheetDialog dialog = new BottomSheetDialog(context, R.style.BottomSheetStyle);
// or method 2 
super(context, R.style.BottomSheetStyle);

答案 3 :(得分:-2)

试试这个

 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();



}