Java Code Examples for android.view.Window#setSoftInputMode()

The following examples show how to use android.view.Window#setSoftInputMode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditFragment.java    From EasyPhotos with Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    Window dialogWindow = getDialog().getWindow();
    if (null != dialogWindow) {
        WindowManager.LayoutParams attrs = dialogWindow.getAttributes();
        attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
        dialogWindow.setAttributes(attrs);
        dialogWindow.requestFeature(Window.FEATURE_NO_TITLE);
    }

    super.onActivityCreated(savedInstanceState);

    if (null != dialogWindow) {
        dialogWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));
        dialogWindow.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
        dialogWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    }
}
 
Example 2
Source File: KeyboardUtils.java    From AndroidUtilCode with Apache License 2.0 6 votes vote down vote up
/**
 * Fix the bug of 5497 in Android.
 * <p>It will clean the adjustResize</p>
 *
 * @param window The window.
 */
public static void fixAndroidBug5497(@NonNull final Window window) {
    int softInputMode = window.getAttributes().softInputMode;
    window.setSoftInputMode(softInputMode & ~WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    final FrameLayout contentView = window.findViewById(android.R.id.content);
    final View contentViewChild = contentView.getChildAt(0);
    final int paddingBottom = contentViewChild.getPaddingBottom();
    final int[] contentViewInvisibleHeightPre5497 = {getContentViewInvisibleHeight(window)};
    contentView.getViewTreeObserver()
            .addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    int height = getContentViewInvisibleHeight(window);
                    if (contentViewInvisibleHeightPre5497[0] != height) {
                        contentViewChild.setPadding(
                                contentViewChild.getPaddingLeft(),
                                contentViewChild.getPaddingTop(),
                                contentViewChild.getPaddingRight(),
                                paddingBottom + getDecorViewInvisibleHeight(window)
                        );
                        contentViewInvisibleHeightPre5497[0] = height;
                    }
                }
            });
}
 
Example 3
Source File: AwesomeFragment.java    From AndroidNavigation with MIT License 6 votes vote down vote up
protected void setupDialog() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setStatusBarTranslucent(true);
    } else {
        setStatusBarTranslucent(presentableActivity.isStatusBarTranslucent());
    }

    Window window = getWindow();
    if (window != null) {
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    }

    Dialog dialog = getDialog();
    if (dialog != null) {
        dialog.setOnKeyListener((dialogInterface, keyCode, event) -> {
            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
                if (!dispatchBackPressed() && isCancelable()) {
                    hideDialog();
                }
                return true;
            }
            return false;
        });
    }
}
 
Example 4
Source File: ActivityUtils.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
/**
 * Show dialog in full width / show keyboard
 *
 * @param dialog Get via dialog.show()
 */
public void dialogFullWidth(AlertDialog dialog, boolean fullWidth, boolean showKeyboard) {
    try {
        Window w;
        if (dialog != null && (w = dialog.getWindow()) != null) {
            if (fullWidth) {
                w.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
            }
            if (showKeyboard) {
                w.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            }
        }
    } catch (Exception ignored) {
    }
}
 
Example 5
Source File: EditTextDialog.java    From PresencePublisher with MIT License 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());

    LayoutInflater inflater = LayoutInflater.from(getContext());
    View view = inflater.inflate(R.layout.dialog_edit_text, null);

    EditText editText = view.findViewById(android.R.id.edit);
    if (editText != null) {
        editText.requestFocus();
        editText.setSelection(0);
        editText.setText(text);
    }

    builder.setTitle(titleId)
            .setView(view)
            .setPositiveButton(R.string.dialog_ok, (dialog, id) -> {
                if (editText != null) {
                    callback.accept(editText.getText().toString());
                } else {
                    HyperLog.e(TAG, "Unable to find edit text field");
                }
            })
            .setNegativeButton(R.string.dialog_cancel, null);
    AlertDialog alertDialog = builder.create();

    Window window = alertDialog.getWindow();
    if (window != null) {
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    }

    return alertDialog;
}
 
Example 6
Source File: EditTextDialogDecorator.java    From AndroidMaterialDialog with Apache License 2.0 5 votes vote down vote up
/**
 * Requests the focus and displays the keyboard.
 */
private void requestFocus() {
    Window window = getWindow();

    if (window != null) {
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    }

    if (editText != null) {
        editText.requestFocus();
    }
}
 
Example 7
Source File: EditPage.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
public void setActivity(Activity activity) {
	super.setActivity(activity);
	Window win = activity.getWindow();
	int orientation = activity.getResources().getConfiguration().orientation;
	if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
		win.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
				| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
	} else {
		win.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
				| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
	}
}
 
Example 8
Source File: DialogPreference.java    From AndroidMaterialPreferences with Apache License 2.0 5 votes vote down vote up
/**
 * Requests the soft input method to be shown.
 */
private void requestInputMode() {
    if (needInputMethod()) {
        Window window = dialog.getWindow();

        if (window != null) {
            window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        }
    }
}
 
Example 9
Source File: EditPage.java    From AndroidLinkup with GNU General Public License v2.0 5 votes vote down vote up
public void setActivity(Activity activity) {
	super.setActivity(activity);
	Window win = activity.getWindow();
	int orientation = activity.getResources().getConfiguration().orientation;
	if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
		win.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
				| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
	} else {
		win.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
				| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
	}
}
 
Example 10
Source File: CommentBottomSheetDialogFragment.java    From TikTok with Apache License 2.0 5 votes vote down vote up
/**
 * 如果想要点击外部消失的话 重写此方法
 *
 * @param savedInstanceState
 * @return
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = super.onCreateDialog(savedInstanceState);
    //设置点击外部可消失
    dialog.setCanceledOnTouchOutside(true);
    //设置使软键盘弹出的时候dialog不会被顶起
    Window win = dialog.getWindow();
    WindowManager.LayoutParams params = win.getAttributes();
    win.setSoftInputMode(params.SOFT_INPUT_ADJUST_NOTHING);

    //这里设置dialog的进出动画
    win.setWindowAnimations(R.style.DialogBottomAnim);
    return dialog;
}
 
Example 11
Source File: DialogPreference.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the required flags on the dialog window to enable input method window to show up.
 */
private void requestInputMethod(Dialog dialog) {
    Window window = dialog.getWindow();
    if (window != null) {
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    }
}
 
Example 12
Source File: EditPage.java    From BigApp_WordPress_Android with Apache License 2.0 5 votes vote down vote up
public void setActivity(Activity activity) {
	super.setActivity(activity);
	Window win = activity.getWindow();
	int orientation = activity.getResources().getConfiguration().orientation;
	if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
		win.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
				| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
	} else {
		win.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
				| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
	}
}
 
Example 13
Source File: MaterialEditTextPreference.java    From 920-text-editor-v2 with Apache License 2.0 4 votes vote down vote up
/**
 * Copied from DialogPreference.java
 */
private void requestInputMethod(Dialog dialog) {
    Window window = dialog.getWindow();
    window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
 
Example 14
Source File: DialogPreference.java    From PreferenceFragment with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the required flags on the dialog window to enable input method window to show up.
 */
private void requestInputMethod(Dialog dialog) {
    Window window = dialog.getWindow();
    window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
 
Example 15
Source File: BubbleDialog.java    From HappyBubble with Apache License 2.0 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        if (mBubbleLayout == null)
        {
            mBubbleLayout = new BubbleLayout(getContext());
        }
        if (mAddView != null)
        {
            mBubbleLayout.addView(mAddView);
        }
        setContentView(mBubbleLayout);

        final Window window = getWindow();
        if (window == null) return;
        if (mSoftShowUp)
        {
            window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        }
        window.setLayout(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

        onAutoPosition();

        setLook();
//        mBubbleLayout.post(new Runnable()
//        {
//            @Override
//            public void run()
//            {
//                dialogPosition();
//            }
//        });
        mBubbleLayout.measure(0, 0);
        dialogPosition();

        mOnGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener()
        {
            int lastWidth, lastHeight;
            @Override
            public void onGlobalLayout()
            {
                if (lastWidth == mBubbleLayout.getMeasuredWidth() && lastHeight == mBubbleLayout.getMeasuredHeight()) return;
                dialogPosition();
                lastWidth = mBubbleLayout.getMeasuredWidth();
                lastHeight = mBubbleLayout.getMeasuredHeight();
            }
        };

        mBubbleLayout.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);


        mBubbleLayout.setOnClickEdgeListener(new BubbleLayout.OnClickEdgeListener()
        {
            @Override
            public void edge()
            {
                if (BubbleDialog.this.mCancelable)
                {
                    dismiss();
                }
            }
        });
    }
 
Example 16
Source File: PreferenceDialogFragment.java    From MaterialPreference with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the required flags on the dialog window to enable input method window to show up.
 */
private void requestInputMethod(Dialog dialog) {
    Window window = dialog.getWindow();
    window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
 
Example 17
Source File: DialogPreference.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the required flags on the dialog window to enable input method window to show up.
 */
private void requestInputMethod(Dialog dialog) {
    Window window = dialog.getWindow();
    window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
 
Example 18
Source File: DialogPreferenceV7.java    From libcommon with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the required flags on the dialog window to enable input method window to show up.
 */
private void requestInputMethod(@NonNull final Dialog dialog) {
	Window window = dialog.getWindow();
	window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
 
Example 19
Source File: EditTextPreferenceCompat.java    From MaterialPreferenceCompat with MIT License 4 votes vote down vote up
private void requestInputMethod(Dialog dialog) {
	Window window = dialog.getWindow();
	window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
 
Example 20
Source File: DialogPreference.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the required flags on the dialog window to enable input method window to show up.
 */
private void requestInputMethod(Dialog dialog) {
    Window window = dialog.getWindow();
    window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}