我正在使用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();}
2 回答

慕妹3242003
TA貢獻1824條經驗 獲得超6個贊
在您的活動 java 類中的 onCreate() 方法上使用以下方法。
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
幾天前,我遇到了同樣的問題。然后在我的onCreate()方法中使用這部分代碼,那么問題就解決了。
樣本:

qq_遁去的一_1
TA貢獻1725條經驗 獲得超8個贊
有幾種方法可以實現這一點:
1.將以下代碼寫入您的 Android Manifest 文件中的<activity>
標簽下:
android:windowSoftInputMode="stateHidden|adjustResize"
2.將以下代碼寫入您onCreate()
的活動方法中:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
我希望它對你有用。
添加回答
舉報
0/150
提交
取消