简体   繁体   English

聚焦edittext时如何显示软键盘

[英]How to show soft-keyboard when edittext is focused

I know their are 100 posts about this one, and somehow it isn't working for me. 我知道他们有100篇关于这个的文章,以某种方式对我来说不起作用。 I got an EditText, and when I "touch" that box, the keyboard must appear. 我得到一个EditText,并且当我“触摸”该框时,必须出现键盘。

This is everything I tried already: 这就是我已经尝试过的一切:

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);

and

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);

and

 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);

and

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);

I even tried to add this in the manifest: 我什至尝试将其添加到清单中:

android:windowSoftInputMode="stateAlwaysVisible"

But I can't get it to work. 但是我无法正常工作。 Probably I forgot something, but I am out of ideas now. 可能我忘记了一些东西,但是现在我没主意了。 Someone got more ideas or the solution? 有人有更多的想法或解决方案吗?

This is my edittext: 这是我的edittext:

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

Try with this.. 试试这个..

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

To Close u can use 关闭您可以使用

  InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
 imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在焦点 EditText 之外单击时隐藏软键盘,但如果单击另一个 EditText 则不隐藏? - How to make the soft keyboard hide when clicked outside of the focused EditText BUT not if another EditText is clicked? 出现EditText时显示软键盘 - Show Soft Keyboard when EditText Appears Android:如何永久且完全不显示 EditText 的默认软键盘? - Android: how to permanently & completely NOT show default soft keyboard for an EditText? 聚焦editText并打开键盘时如何移动视图? - How to move view when editText is focused and keyboard is open? Android中的软键盘压缩文本编辑框 - Soft-keyboard squeezes textedit box in Android 软键盘隐藏EditText - Soft keyboard hides EditText 在循环器视图中切换到下一个EditText时,如何保持软键盘的连接? - How can I keep the soft keyboard up when switching to the next EditText in a recycler view? 当设备处于横向模式时显示软键盘 - Show soft keyboard when the device is landscape mode 当edittext在软键盘后面时,在android对话框上调整平移 - Adjusting pan on android dialog when edittext is behind the soft keyboard Android 自定义 ListView - 当软键盘隐藏时 Edittext 被清除 - Android custom ListView - Edittext gets cleared when the soft keyboard hides
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM