Android 软键盘显示在对话框 fragment 下

标签 android listview android-fragments keyboard

我有一个对话框 fragment ,其中有一个 ListView ,其中列出了多个 View ,在该 View 之一中有一个显示光标的编辑文本,但未显示软键盘。 所以我在它的 onclick 上写了一个代码来显示键盘,如下所示,

etcomment.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    InputMethodManager imm = (InputMethodManager) activity
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
                }
            });

现在键盘已显示,但它显示在 DialogFragment

enter image description here

我搜索了但没有得到答案,请帮助我!

最佳答案

你的窗口参数是问题好吧你应该这样做:..

    Dialog dialog = new Dialog(DialogTestKeyboard.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width  = 400;
    lp.height = 800;
    dialog.setContentView(yourLayoutHavingEditText);
    dialog.setCancelable(false);
    dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    dialog.show();
    dialog.getWindow().setAttributes(lp);
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

关于Android 软键盘显示在对话框 fragment 下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30543658/

相关文章:

android - 使用 Xposed 在另一个应用程序中 Hook 私有(private)方法

java - 有没有办法在Azure MobileServiceSyncTable中进行计数查询?

android - 不同layout xml中的id一定不一样吧?

android - 运行xcode时出现词法错误

android - 布局太高的地方未显示 ListView

java - Android 上的 Activity 和 ListView 问题

c# - 在 asp.net 中仅从 ListView 中获取最后一行值

android - 在同一 fragment 中合并 Map 和 ListView

android - 在 onSaveInstanceState 之后无法执行此操作 - DialogFragment

java - FragmentTransaction 类型中的方法 add(int, Fragment) 不适用于参数 (int, WeatherFragment)