我正在尝试显示带有一些EditText字段的BottomSheetDialogFragment,供用户输入信息.我想直接在键盘上方显示它,但它会不断覆盖内容.
当我调出BottomSheetDialogFragment时会发生这种情况,您可以看到它正在选择卡号EditText,但覆盖其他内容.
理想情况下,这就是我正在寻找的,你可以看到EditTexts和View的填充.
我尝试了很多围绕windowSoftInputMode的解决方案,但似乎没有任何效果.我已将它设置为父Activity的adjustResize和实际的BottomSheetDialogFragment via
dialog.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
而且我也尝试修改我的布局,将它从FrameLayout更改为ScrollView到CoordinatorLayout,看看它是否对布局的位置有任何影响,但似乎没有任何效果.
如果有人知道如何做到这一点,那将非常感谢,谢谢.
解决方法
以下步骤可能有助于解决您的问题.
- android:imeOptions="actionSend|flagNoEnterAction"
例如:
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:inputType="number"
- android:hint="Card number"
- android:imeOptions="actionSend|flagNoEnterAction"/>
然后在AndroidManifest.xml文件中的activity标记上添加以下行
- android:windowSoftInputMode="stateVisible|adjustResize"
例如:
- </activity>
- <activity android:name=".stack.MainActivity"
- android:windowSoftInputMode="stateVisible|adjustResize">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
您可以从HERE找到有关屏幕输入法的更多详细信息.