java - 键盘隐藏 BottomSheetDialog
问题描述
我正在使用BottomSheetDialog从客户那里获取一些输入,当用户单击TextInputLayout时,我的视图包含TextInputLayout和TextInputLayout下方的按钮,下面的按钮被键盘隐藏,所以我需要键盘上方的那个按钮,尝试了很多可能性但是无法修复它。附上有关它的图片。
Java 文件(活动)代码:
BottomSheetDialog customTipAmountBottomSheetDialog;
private void showCustomTipAmountBottomSheet() {
customTipAmountBottomSheetDialog = new BottomSheetDialog(OrderActivity.this);
View customTipAmountBottomSheetView = getLayoutInflater().inflate(R.layout.custom_tip_amount_bottom_sheet, null);
customTipAmountBottomSheetDialog.setContentView(customTipAmountBottomSheetView);
InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
assert imm != null;
imm.showSoftInput(binding.invoiceDialog.submit, InputMethodManager.RESULT_HIDDEN);
TextInputLayout customTipAmountBSTIL = customTipAmountBottomSheetView.findViewById(R.id.customTipAmountBSTIL);
EditText customTipAmountBSET = customTipAmountBottomSheetView.findViewById(R.id.customTipAmountBSET);
ImageView submit_custom_tip_amount = customTipAmountBottomSheetView.findViewById(R.id.submit_custom_tip_amount);
submit_custom_tip_amount.setOnClickListener(view -> {
String amount = customTipAmountBSET.getText().toString();
if (amount.length() > 0 && Integer.parseInt(amount) > 0) {
int tipAmount = Integer.parseInt(amount);
if (tipAmount > 0 && tipAmount < 51) {
binding.invoiceDialog.customTipAmountTv.setText(tipAmount);
captainTipAmount = tipAmount;
customTipAmountBottomSheetDialog.dismiss();
} else {
customTipAmountBSTIL.setError("Amount should be less than 50");
}
} else {
customTipAmountBSTIL.setError("Requires a valid amount");
}
});
customTipAmountBottomSheetDialog.show();
}
布局文件 custom_tip_amount_bottom_sheet.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:layout_height="match_parent">
<TextView
android:id="@+id/customTipAmountCaptainNameTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="Tip amount for Rapido Captain"
android:textColor="@color/black"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.design.widget.TextInputLayout
android:id="@+id/customTipAmountBSTIL"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:hint="Enter amount"
app:boxBackgroundColor="@color/grey_100"
app:boxCornerRadiusTopEnd="8dp"
app:boxCornerRadiusTopStart="8dp"
app:errorEnabled="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/customTipAmountCaptainNameTv">
<EditText
android:id="@+id/customTipAmountBSET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="1234567890"
android:ems="2"
android:focusable="true"
android:imeOptions="actionDone"
android:inputType="phone" />
</android.support.design.widget.TextInputLayout>
<ImageView
android:id="@+id/submit_custom_tip_amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="submitFeedbackConfirmationPopUp"
android:padding="@dimen/margin_8"
app:layout_constraintBottom_toBottomOf="@+id/customTipAmountBSTIL"
app:layout_constraintEnd_toEndOf="@+id/customTipAmountBSTIL"
app:layout_constraintTop_toTopOf="@+id/customTipAmountBSTIL"
app:srcCompat="@drawable/ic_arrow_forward_black_24dp" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/submit_custom_tip_amount" />
在活动文件的清单文件中:
android:windowSoftInputMode="adjustPan"
尝试了很多搜索,但仍然无法修复它。我得到了一个与我的问题相关的答案,但它是使用 BottomSheetFragment()键盘隐藏 BottomSheetFragment,但我需要使用 BottomSheetDialog。请有人帮我解决这个问题。
让我知道还需要什么其他信息。
解决方案
推荐阅读
- java - 如果程序从 Eclipse IDE 或编译的二进制 java 运行,则设置一个 bool 变量
- javascript - 带有 Next.js 的 GSAP ScrollTrigger
- ios - 打印系统枚举值的描述只打印枚举名称
- javascript - JS:UI 中的类使用示例?
- r - 新列保持 r 中另一列的第一次出现
- python - 如何缩短数据框数据的名称
- javascript - 我不断收到此错误“TypeError:无法读取未定义的属性“原型”
- powershell - ErrorActionPreference=stop 停止所有脚本堆栈
- mysql - 允许用户创建只有自己权限的数据库
- python - 在 Flask 应用程序工厂中初始化 RotatingFileHandler 日志记录时出现权限错误