【问题标题】:Android BottomSheetDialog with EditText covered by keyboard带有键盘覆盖的EditText的Android BottomSheetDialog
【发布时间】:2020-01-19 09:19:46
【问题描述】:

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>

【问题讨论】:

标签: android android-softkeyboard


【解决方案1】:
<?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>

【讨论】:

    【解决方案2】:

    将此添加到您的课程中:

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

    上面的代码行会将你的布局向上推,以使 EditText 在它具有焦点和键盘时可见。

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

        【解决方案4】:

        试试这个

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-08-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多