0

我知道他们有 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>
4

1 回答 1

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);
于 2012-02-28T09:17:11.793 回答