【问题标题】:How to prevent Soft Keyboard hiding button in custom dialog?如何防止自定义对话框中的软键盘隐藏按钮?
【发布时间】:2017-06-07 10:54:43
【问题描述】:

我有一个自定义对话框,如下所示

当软键盘出现时,它会隐藏如下所示的按钮。

我的代码

https://mcaf.ee/9qhnef

如何避免提交按钮被隐藏?我已经添加了自动调整大小和自动平移,但到目前为止还没有运气。

【问题讨论】:

标签: android


【解决方案1】:

将您的整个属性添加到一个线性布局中并放入滚动视图中。我希望这对你有帮助。

【讨论】:

    【解决方案2】:

    当我不得不实现一个高度几乎与屏幕高度匹配的反馈对话框时,我也遇到了同样的问题。您需要将 ScrollView 添加到 xml 文件中视图的父布局,例如。

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        //your content View goes here
    
      </ScroolView>
    

    然后在片段中膨胀视图之后, 在你的 onCreateView 上试试这个:

     getDialog().getWindow()
    .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    

    SOFT_INPUT_ADJUST_RESIZE 的作用与在清单文件中定义的活动情况一样。希望这会有所帮助。

    【讨论】:

      【解决方案3】:

      用下面的 xml 更新你的 Linked 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="match_parent"
          android:background="#1260C5"
          android:orientation="vertical">
      
          <ScrollView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_weight="1"
              android:alpha=".85">
      
              <LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:orientation="vertical">
      
                  <LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:alpha=".5"
                      android:gravity="center"
                      android:orientation="vertical">
      
                      <ImageButton
                          android:id="@+id/imgNotificationClose"
                          android:layout_width="50dp"
                          android:layout_height="50dp"
                          android:background="#00000000"
                          android:scaleType="fitCenter"
                          android:src="@mipmap/ic_launcher" />
      
                      <TextView
                          android:id="@+id/txtNotification"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:gravity="center"
                          android:text="CHANGE PASSWORD"
                          android:textAppearance="@style/TextAppearance.AppCompat.Large"
                          android:textSize="36sp"
                          android:visibility="gone" />
      
                  </LinearLayout>
      
      
                  <LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_marginTop="5dp"
                      android:gravity="top"
                      android:orientation="vertical">
      
      
                      <TextView
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
      
                          android:layout_marginLeft="20dp"
                          android:layout_marginRight="20dp"
                          android:gravity="left|center"
                          android:text="Email"
                          android:textStyle="bold" />
      
                      <EditText
                          android:id="@+id/old_email"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:layout_marginBottom="15dp"
                          android:layout_marginLeft="20dp"
                          android:layout_marginRight="20dp"
                          android:background="#FFFFFF"
                          android:focusable="false"
                          android:padding="10dip"
                          android:paddingLeft="30dp"
                          android:paddingRight="30dp"
                          android:textColor="#000000"
                          android:textSize="14sp" />
      
                      <TextView
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
      
                          android:layout_marginLeft="20dp"
                          android:layout_marginRight="20dp"
                          android:gravity="left|center"
                          android:text="Old Password"
                          android:textStyle="bold" />
      
      
                      <EditText
                          android:id="@+id/password_change_edit_password_current_pass"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:layout_marginBottom="15dp"
                          android:layout_marginLeft="20dp"
                          android:layout_marginRight="20dp"
                          android:background="#FFFFFF"
                          android:inputType="textPassword"
                          android:padding="10dip"
                          android:paddingLeft="30dp"
                          android:paddingRight="30dp"
                          android:textColor="#000000"
                          android:textSize="14sp" />
      
                      <TextView
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
      
                          android:layout_marginLeft="20dp"
                          android:layout_marginRight="20dp"
                          android:gravity="left|center"
                          android:text="New Password"
                          android:textStyle="bold" />
      
                      <EditText
                          android:id="@+id/password_change_edit_password_new_pass"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:layout_marginBottom="15dp"
                          android:layout_marginLeft="20dp"
                          android:layout_marginRight="20dp"
                          android:background="#FFFFFF"
                          android:ems="10"
                          android:inputType="textPassword"
      
                          android:padding="10dip"
                          android:paddingLeft="30dp"
                          android:paddingRight="30dp"
                          android:textColor="#000000"
                          android:textSize="14sp" />
      
                      <TextView
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
      
                          android:layout_marginLeft="20dp"
                          android:layout_marginRight="20dp"
                          android:gravity="left|center"
                          android:text="Confirm New Password"
                          android:textSize="14sp"
                          android:textStyle="bold" />
      
                      <EditText
                          android:id="@+id/password_change_edit_password_confirm_pass"
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:layout_marginBottom="15dp"
                          android:layout_marginLeft="20dp"
                          android:layout_marginRight="20dp"
                          android:background="#FFFFFF"
                          android:ems="10"
                          android:inputType="textPassword"
      
                          android:padding="10dip"
                          android:paddingLeft="30dp"
                          android:paddingRight="30dp"
                          android:textColor="#000000"
                          android:textSize="14sp" />
      
      
                      <LinearLayout
                          android:layout_width="match_parent"
                          android:layout_height="wrap_content"
                          android:layout_gravity="center_horizontal"
                          android:layout_marginTop="10dp"
                          android:orientation="horizontal">
      
                          <ImageView
                              android:id="@+id/img_alert"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:src="@mipmap/ic_launcher"
                              android:visibility="invisible" />
      
      
                          <TextView
                              android:id="@+id/password_change_validation_status"
                              android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:layout_gravity="center"
                              android:gravity="center"
                              android:text=""
                              android:textColor="#BEB2D1"
                              android:textSize="14sp"
                              android:textStyle="bold" />
      
                      </LinearLayout>
      
                  </LinearLayout>
      
      
              </LinearLayout>
          </ScrollView>
      
          <RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_weight="0">
      
              <Button
                  android:id="@+id/password_change_btn_password_submit"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginBottom="15dp"
                  android:layout_marginLeft="20dp"
                  android:layout_marginRight="20dp"
                  android:layout_marginTop="20dp"
                  android:paddingLeft="30dp"
                  android:paddingRight="30dp"
                  android:text="Submit"
                  android:textColor="#FFFFFF"
                  android:textSize="18sp" />
      
          </RelativeLayout>
      
      </LinearLayout>
      

      【讨论】:

        【解决方案4】:

        你可以试试这个:

        dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        

        或者在 XML 中你可以改变这个:

        android:focusable="true"
        android:focusableInTouchMode="true"
        

        【讨论】:

        • 但是 xml 到底在哪里?父布局还是编辑文本?
        【解决方案5】:

        我有类似的问题,我发现问题是因为它是全屏。尝试从您的styles.xml删除这个(如果有的话):

         <item name="android:windowFullscreen">true</item>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-12-22
          • 1970-01-01
          • 2012-07-22
          • 1970-01-01
          • 1970-01-01
          • 2019-06-17
          • 1970-01-01
          相关资源
          最近更新 更多