android.view.Window#setSoftInputMode ( )源码实例Demo

下面列出了android.view.Window#setSoftInputMode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: EasyPhotos   文件: EditFragment.java
@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);
    }
}
 
源代码2 项目: AndroidNavigation   文件: AwesomeFragment.java
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;
        });
    }
}
 
源代码3 项目: AndroidUtilCode   文件: KeyboardUtils.java
/**
 * 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;
                    }
                }
            });
}
 
源代码4 项目: PresencePublisher   文件: EditTextDialog.java
@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;
}
 
源代码5 项目: BigApp_WordPress_Android   文件: EditPage.java
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);
	}
}
 
源代码6 项目: Nimingban   文件: DialogPreference.java
/**
 * 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);
    }
}
 
源代码7 项目: TikTok   文件: CommentBottomSheetDialogFragment.java
/**
 * 如果想要点击外部消失的话 重写此方法
 *
 * @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;
}
 
源代码8 项目: AndroidLinkup   文件: EditPage.java
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);
	}
}
 
/**
 * 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);
        }
    }
}
 
源代码10 项目: BigApp_Discuz_Android   文件: EditPage.java
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);
	}
}
 
/**
 * 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();
    }
}
 
源代码12 项目: openlauncher   文件: ActivityUtils.java
/**
 * 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) {
    }
}
 
源代码13 项目: android_9.0.0_r45   文件: DialogPreference.java
/**
 * 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);
}
 
private void requestInputMethod(Dialog dialog) {
	Window window = dialog.getWindow();
	window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
 
源代码15 项目: MHViewer   文件: DialogPreference.java
/**
 * 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);
}
 
/**
 * Copied from DialogPreference.java
 */
private void requestInputMethod(Dialog dialog) {
    Window window = dialog.getWindow();
    window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
 
源代码17 项目: PreferenceFragment   文件: DialogPreference.java
/**
 * 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);
}
 
源代码18 项目: HappyBubble   文件: BubbleDialog.java
@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();
                }
            }
        });
    }
 
/**
 * 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);
}
 
源代码20 项目: libcommon   文件: DialogPreferenceV7.java
/**
 * 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);
}