【问题标题】:EditText in PopupWindow not showing keyboard even if setFocusable(true)即使 setFocusable(true),PopupWindow 中的 EditText 也不显示键盘
【发布时间】:2014-03-14 16:08:59
【问题描述】:

我似乎无法完成这项工作。我已经将 popWindow 设置为可聚焦于我在其他论坛上阅读的内容,但仍然没有运气。

xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:background="@drawable/popbg"
android:orientation="vertical" >

<Button
    android:id="@+id/cancel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:layout_marginRight="10dp"
    android:layout_marginTop="30dp"
    android:background="@drawable/zcancel" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:layout_marginLeft="10dp"
    android:text="SSID"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
    android:id="@+id/editText3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textPersonName" />

java

 case(R.id.settings):
 switch (event.getAction()) 
 {
case MotionEvent.ACTION_DOWN:
v.setBackgroundResource(R.drawable.cpanel2);
return true;
case MotionEvent.ACTION_UP:
v.setBackgroundResource(R.drawable.cpanel1);

LayoutInflater layoutInflater =  
    (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);  

View popSwitchView = layoutInflater.inflate(R.layout.settings_xml, null);

final PopupWindow popWindow = new PopupWindow(popSwitchView);
popWindow.setWidth(LayoutParams.MATCH_PARENT);
popWindow.setHeight(LayoutParams.MATCH_PARENT);
popWindow.showAtLocation(popSwitchView, Gravity.CENTER, 0, 0);
popWindow.setOutsideTouchable(false);  
popWindow.setFocusable(true);
Drawable d = getResources().getDrawable(R.drawable.popbg); 
popWindow.setBackgroundDrawable(d);

Button CancelButton = (Button)popSwitchView.findViewById(R.id.cancel);

CancelButton.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
popWindow.dismiss();
}
});

                    popWindow.showAsDropDown(v, 50, -30);

                    return true;
                default:
                    return false;


            }

我正计划为网络配置创建一个设置弹出窗口。我似乎无法修复我的代码以便为你们提供良好的视图。

【问题讨论】:

  • 试试thisthis
  • 不能用弹窗来完成吗?我需要使用对话框片段吗? ,我把所有的东西都放在了第二个中,我真的不明白为什么仍然没有。不工作。

标签: android keyboard android-edittext popupwindow


【解决方案1】:

哈,.找到了答案。, 刚刚做了

popWindow.setFocusable(true);
popWindow.update();

感谢您的支持! 该主题的学分 Keyboard not shown when i click on edittextview in android?

【讨论】:

  • 正如我们在爱尔兰所说的那样,以上帝的名义
【解决方案2】:

这对我有用:

popWindow.setFocusable(true);
popWindow.update();

【讨论】:

  • 大卫感谢您的反馈,但它的工作和工作对我来说很好,为什么你投票为 -1 我没有得到
【解决方案3】:

尝试在显示弹出窗口之前添加此行:

popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

【讨论】:

    【解决方案4】:

    没有任何帮助,它仍然没有出现在某些设备上,所以我不得不强制显示它(kotlin):

    val editText = customView.findViewById<EditText>(numberFieldId)
            editText.onClick {
                showKeyboard(editText, context)
            }
    
    private fun showKeyboard(mEtSearch: EditText, context: Context) {
            mEtSearch.requestFocus()
            val imm = context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
            imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0)
        }
    

    【讨论】:

      【解决方案5】:

      试试这个::

      以编程方式:

      edittext.requestFocus();
      

      通过xml:

      <EditText
      android:id="@+id/editText3"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:ems="10"
      android:inputType="textPersonName">
          <requestFocus />
      </EditText>
      

      希望对你有帮助!!

      【讨论】:

      • 应该选择这个答案
      猜你喜欢
      • 1970-01-01
      • 2019-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-23
      • 2021-01-27
      • 2011-03-20
      相关资源
      最近更新 更多