Android:在自定义编辑文本中触发softkeaboard

发布于 2024-09-14 13:50:47 字数 665 浏览 3 评论 0原文

我想显示软键盘,但它不起作用。 这是我的代码:

 public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        myTextView myTextView = new myTextView(this);

        setContentView(myTextView);
    }

public class myTextView extends EditText{

public boolean onTouchEvent(){

if(action == ACTION_DOWN){

super.onTouchEvent(event);

} }

当我触摸屏幕时,软键盘不会出现,但会出现alertDialog“编辑文本”,当您长时间触摸它们时,它会出现在正常的编辑文本上。 onCreate 中的这段附加代码没有任何影响:

InputMethodManager input = (InputMethodManager) 
getSystemService(Context.INPUT_METHOD_SERVICE);
input.showSoftInput(myTextView, 0);

感谢帮助, Fr4gg0r

I want to show the softkeyboard, but it does not work.
Here is my code:

 public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        myTextView myTextView = new myTextView(this);

        setContentView(myTextView);
    }

public class myTextView extends EditText{

public boolean onTouchEvent(){

if(action == ACTION_DOWN){

super.onTouchEvent(event);

} }

When i touch the screen, the softkeyboard does not appear, but the alertDialog "edit text" appears, which appears on normal edittexts when you long touch them.
This additional code in the onCreate has no affection:

InputMethodManager input = (InputMethodManager) 
getSystemService(Context.INPUT_METHOD_SERVICE);
input.showSoftInput(myTextView, 0);

Thanks for help,
Fr4gg0r

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

长安忆 2024-09-21 13:50:47

试试这个 -

    myTextView.setOnFocusChangeListener(
            new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    if (hasFocus)
                              getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                }
            });

Try this -

    myTextView.setOnFocusChangeListener(
            new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    if (hasFocus)
                              getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                }
            });
生寂 2024-09-21 13:50:47

我很抱歉这么晚才回答..
所以我使用以下命令尝试了您的代码:
myTextView.requestFocus();
但键盘不显示。

我必须更正我的文字:
在模拟器上,键盘不会显示,但在我的三星 Galaxy S 上,它会显示! :o

I'm very sorry this very late answer..
So I tried your code with the following command:
myTextView.requestFocus();
But the keyboard does not show up.

I have to correct my text:
On the emulator, the keyboard does not show up, but on my Samsung Galaxy S, it does! :o

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文