【问题标题】:popping keyboard in android在android中弹出键盘
【发布时间】:2017-01-09 09:45:32
【问题描述】:

我创建了一个使用视图的应用程序,现在我希望在触摸视图时弹出键盘,即用户名、地址或电话视图我使用了以下代码行,但它不起作用

1)getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

这不起作用,我也尝试了以下但没有帮助

((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE))
            .showSoftInput(username, InputMethodManager.SHOW_FORCED);

请帮我解决这个问题。This is the image of my custom view app

我的 EditText XML 在这里

<com.github.florent37.materialtextfield.MaterialTextField    
       android:layout_below="@+id/view" 
       app:mtf_image="@drawable/phon" android:id="@+id/view3"> 
<EditText android:layout_width="wrap_content" 
          android:layout_height="40dp" 
          android:id="@+id/phoneNo"
          android:focusableInTouchMode="true"
          android:textSize="18sp"
          android:inputType="phone" 
          android:background="@drawable/phone"
          android:hint="Phone Number" />
</com.github.florent37.materialtextfield.MaterialTextField>

【问题讨论】:

  • 您是否在布局中使用 EditText :
  • 是的,我正在使用编辑文本。
  • 用户名是您的editText吗?
  • 在此处复制您的用户名 XML。
  • xml太长了,这里无法复制

标签: android view textfield android-custom-view


【解决方案1】:

尝试以下:

InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.toggleSoftInputFromWindow(mMessage.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);

mMessage 是您的编辑文本。

【讨论】:

  • 另外,我曾经在打开键盘时使用 EditText.requestFocus()。如果它不起作用,也试试。
  • 这些方法都不起作用,我不知道为什么,我在 genymotion 模拟器中这样做,但键盘没有显示
  • 你也可以在物理设备上尝试一次吗?
  • 其实我没有物理设备这就是为什么
猜你喜欢
  • 1970-01-01
  • 2015-06-06
  • 2014-12-01
  • 2015-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-30
  • 2012-12-23
相关资源
最近更新 更多