在android中弹出键盘

时间:2016-09-01 13:21:18

标签: android view textfield android-custom-view

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

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>

1 个答案:

答案 0 :(得分:0)

请尝试以下操作:

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

其中mMessage是您的编辑文本。

相关问题