如何在关注edittext时显示软键盘

时间:2012-02-28 09:09:19

标签: java android keyboard android-edittext android-input-method

我知道他们有关于这个的100个帖子,不知何故它对我不起作用。 我有一个EditText,当我“触摸”那个盒子时,必须出现键盘。

这是我尝试过的所有内容:

public void onClick(View v) {
             EditText Edit_perceel_nr2 = (EditText)findViewById(R.id.Perceel_nr2);;
             InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
             imm.hideSoftInputFromWindow(Edit_perceel_nr2.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

public void onClick(View v) {
             EditText Edit_perceel_nr2 = (EditText)findViewById(R.id.Perceel_nr2);;
             InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
             imm.hideSoftInputFromWindow(Edit_perceel_nr2.getWindowToken(), 0);

 public void onClick(View v) {

             EditText Edit_perceel_nr2 = (EditText)findViewById(R.id.Perceel_nr2);;
             ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(Edit_perceel_nr2, 0);

public void onClick(View v) {

             EditText Edit_perceel_nr2 = (EditText)findViewById(R.id.Perceel_nr2);;
             ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(Edit_perceel_nr2, InputMethodManager.SHOW_IMPLICIT);

我甚至尝试在清单中添加它:

android:windowSoftInputMode="stateAlwaysVisible"

但我无法让它发挥作用。 可能我忘记了什么,但我现在已经没有想法了。 有人有更多想法或解决方案吗?

这是我的编辑文字:

<EditText
    android:id="@+id/Perceel_nr2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="number"
    android:text="text"> 
</EditText>

1 个答案:

答案 0 :(得分:4)

试试这个..

EditText yourEditText= (EditText) findViewById(R.id.yourEditText);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);

要关闭你可以使用

  InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
 imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
相关问题