Development issue/problem:

I will set up a user interface where the bottom sheet is displayed with EditText above the keyboard, allowing the user to enter a value. The problem is that the view partially overlaps the keyboard and covers the lower part of the lower tray.

Here is the bottom sheet and no keyboard.

Here is the bottom sheet with a picture of the keyboard.

What is the best way to ensure that the entire bottom sheet is displayed?

Thank you!

How can I solve this problem?

Solution 1:

I just posted @jblejder of this keyboard problem hiding the BottomSheetDialogFragment, because it worked for me to make it easier for others to find it:

The most practical way I’ve found to change this is to create a style:

And put this in the onCreate method of your BottomSheetDialogFragment :

lift fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(DialogFragment.STYLE_NORMAL, R.style.DialogStyle)
}

This is what it looks like on my camera:

==== UPDATE

As mentioned several times in the comments, you may also need to set the BottomSheetDialog status to STATE_EXPANDED, as in the following reply by Nordknight.

dialog = new BottomSheetDialog(getContext(), R.style.BottomSheetDialog);
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void opShow(DialogInterface dialog)) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
BottomSheetDialog d = (DialogSheet background);
FrameLayout bottomSheet = d.findViewById(R.id).design_bottom_sheet);
BottomSheetBehavior.bottomSheetBehavior.from(bottomSheet);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
},0);
}
})

Solution 2:

dialog = new BottomSheetDialog(getContext(), R.style.BottomSheetDialog);
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void opShow(DialogInterface dialog)) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
BottomSheetDialog d = (DialogSheet background);
FrameLayout bottomSheet = d.findViewById(R.id).design_bottom_sheet);
BottomSheetBehavior.bottomSheetBehavior.from(bottomSheet);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
},0);
}
})

This code works perfectly in the onCreateView method (thanks to ADM)

Solution 3:

This may be an unnecessary reaction. But I’m just pointing out the problem.
When using the BottomSheetDialogFragment, the only option is to set the android:windowIsFloating attribute to true. This way the whole window is above what should be behind it.

Then put this style in onCreate() in your dialog.

lift fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// set window without floating style
setStyle(DialogFragment.STYLE_NORMAL, R.style.AppRoundedBottomSheetDialogThemeNoFloating)
}

This is useful for those who frequently use subpages and want to address the overlap between EditText and softkeys.

Pay attention: The KeyboardUtil class in mikepenz has a problem: on some phones, the content view with the input field automatically clicks on the keyboard, even though the bottom padding covers the entire included content view.

Solution 4:

A dialogue on content can be useful in this context. It opens with the soft key when the focus is on text editing, but the user can always close the soft key and the dialog box is reset at the bottom. When you refocus, the dialog box appears at the top of the keypad.

public void showDialog() {
final BottomSheetDialog=new BottomSheetDialog(this);
dialog.setContentView(R.layout.item_dialog);
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
dialog.show();
}.

You can expand the BottomSheet dialog box using the keyboard. However, to do this, you need to name it after SoftKeyboard Open. Developing the code – .

BottomSheetDialog d = (BottomSheetDialog) ;
FrameLayout bottomSheet = (FrameLayout) d.findViewById(android.support.design.R.id.design_bottom_sheet) ;
BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED) ;

I tested it with DialogInterface.OnShowListener(), but it doesn’t work. Tested with a one second delay. But procrastination is not the answer. You need to know what action to extend the dialogue to.

final BottomSheetDialog=new BottomSheetDialog(this);
dialog.setContentView(R.layout.item_dialog);
dialog.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE|
WindowManager.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
FrameLayout bottomSheet = (FrameLayout) dialog.findViewById(android.support.design.R.id.design_bottom_sheet);
BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED);
}
},2000);
dialog.show() ;

Solution no. 5:

This one works.

BottomSheetDialog = new BottomSheetDialog (this, R.style.DialogStyle);
view sheetView = getLayoutInflater().inflate(R.layout.dialog_remark, null);
Objects.requireNonNull(dialog.getWindow())
.setSoftInputMode(SOFT_INPUT_STATE_VISIBLE);
dialog.setContentView(sheetView);
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(dialogInterface dialog) {
BottomSheetDialog d = (bottom sheet dialog);
View bottomSheetInternal = d.findViewById(com.)google.android.material.R.id.design_bottom_sheet);
BottomSheetBehavior.from(bottomSheetInternal).setState(BottomSheetBehavior.STATE_EXPANDED);
}
});
dialog.show() ;

Add this style to your style.xml

To add a layout

Solution no. 6:

Some answers seem to do the job better than others, but need to be adjusted when using new material design components instead of the old support libraries and when using kotlin.

I hope that helps someone.

BottomSheetDialog(this, R.style.DialogStyle).apply {
setContentView(layoutInflater.inflate(R.layout.bottom_sheet, null))
window ?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
findViewById(R.id.time_et) ?.requestFocus()

show()
}

layout / background_sheet.xml

styles.xml (split for v-21 to use statusBarColor)

Solution no. 7:

I have found that AlertDialog is the best tool for this. Although it is not equal to the bottom or sides of the screen, it is still very nice.

First make an AlertDialog with your opinion.

type val = LayoutInflater.from(context).inflate(R.layout.alert, null)

dialog = AlertDialog.Builder(context)
.setView(view)
.create()

Then adjust the gravity.

dialogue.attributes.gravity = gravity.BOTTOM

And finally, show it.

dialogue.show()

You can also bind the keyboard to stay in the dialog box using the onDismissListener.

After displaying AlertDialog, I turn on the keyboard.

Mention this method in your EditText.

fun showKeyboard(view : view ?) {
if (view == null) return ;

val imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
}

And for firing OnDissListener.

private fun hideKeyboard() {
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0)
}

Solution no. 8:

My answer may be useful to someone who is still looking for a solution. When the keyboard closes the editable text in the BottomSheetDialogFragment, create an instance of the KeyboardUtil class in the setupDialog() method and pass the root view.

@General
public void setupDialog(last Dialog, in style) {
super.setupDialog(dialog, style);
View = View.inflate(getActivity(), R.layout.reopen_dialog_layout, null);
new KeyboardUtil(getActivity(), view);
}

Create new class

public class KeyboardUtil {
private View decorView;
private View contentView;
// little help to show the focus of editText
ViewTreeObserver.onGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
//r is filled with the view coordinates that are still visible.
decorView.getWindowVisibleDisplayFrame(r) ;

//Get screen height and calculate the difference from the usable range of r
int height = decorView.getContext().getResources().getDisplayMetrics().heightPixels ;
int diff = height – r.bottom ;

//If it could be a keyboard, add padding to the display if (diff != 0) {//if the screen height to be used is different from the total screen height, assume a keyboard is displayed now//Check if padding is 0 (if so, set padding for keyboard)if (contentView)getPaddingBottom() != diff) {//Set padding for keyboard contentView.setPadding(0, 0, 0, diff);}} else {//Check if padding != 0 (if so, reset padding)if (contentView.getPaddingBottom() != 0) {// Reset padding contentViewcontentView.setPadding(0, 0, 0);}}}}}

public KeyboardUtil(ActivityPress, View ContentView) {
this.decorView = act.getWindow().getDecorView();
this.contentView = contentView ;

// only for newer versions of Android. worked at API 19
level if (Build.VERSION.SDK_INT >= 19) {
decorView.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener);
}
}

/*** Hide keyboard utility** @param act*/public static void hideKeyboard(Activity act) {if (act != null && act.getCurrentFocus())!= {InputMethodManager inputMethodManager = (InputMethodManager) act.getSystemService(Act.INPUT_METHOD_SERVICE);inputMethodManager.hideSoftInputFromWindow(act.getCurrentFocus().getWindowToken(), 0);}}}

public void enable() {
if (Build.VERSION.SDK_INT >= 19) {
decView.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener);
}
}

public void disable() {
if (Build.VERSION.SDK_INT >= 19) {
decorView.getViewTreeObserver().removeOnGlobalLayoutListener(onGlobalLayoutListener);
}
}
}

Solution no. 9:

private fun enterMobileNumberPopUp() {
trap dialog = BottomSheetDialog(this,R.style.DialogStyle)
trap view = layoutInflater.inflate(R.layout.layout_otp, null)
dialog.setContentView(view)
dialog.behavior.state = BottomSheetBehavior.STATE_EXPANDED
dialog.show() }.

  • THIS IS THE EASTERN AND BEST DIAGNOSIS POSSIBILITY
    GROUPS TO IMPROVE THIS METHOD Show entire bottom sheet with EditText above Keyboard – here

Style Coupler

Good luck!

 soft_input_adjust_resize deprecatedandroid:windowisfloatingscrollview in bottomsheetdialog androidbottomsheetdialogfragment adjustresizebottom sheet dialog fragmentadjustpan

You May Also Like

How Mina Nada, Co- Founder And CEO Of Zoomo Raised $15.6M To Create The Next Evolution In Mobility?

Bookmark(0) Log in to favorites No account yet? Login Mina Nada has…

“The following SDK components were not installed: sys-img-x86-addon-google_apis-google-22 and addon-google_apis-google-22” –

Development issue/problem: I am a Windows 7 64-bit user and I have…