SoftKeyboard不显示新显示片段 [英] SoftKeyboard does not display for a newly displayed Fragment

查看:164
本文介绍了SoftKeyboard不显示新显示片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个FragmentActivity最初,上面有几个按钮会显示一个片段。 当您单击其中一个按钮时,FragmentActivity显示一些EDITTEXT领域的一个新片段。我似乎无法得到软键盘输入,显示我的EDITTEXT领域的新片段时显示。

I have a FragmentActivity that initially displays a fragment with a few buttons on it. When you click one of the buttons, the FragmentActivity displays a new fragment with some editText fields. I can't seem to get the soft input keyboard to display when my new fragment with the editText fields is displayed.

使用在清单中的windowSoftInput模式出来的,显示键盘的时候了。

Using the windowSoftInput mode on the manifest is out as that displays the keyboard right away.

 android:windowSoftInputMode="stateUnchanged"

我曾试过用

<$c$c>getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)

无济于事。 以下是我从我的活动显示新的片段:

to no avail. Here's how I display the new fragment from my Activity:

public void clickHandler(View view) {
        switch (view.getId()) {
        case R.id.login:
            loginFragment = new LoginFragment();
            FragmentTransaction transaction = getSupportFragmentManager()
                    .beginTransaction();

            transaction.replace(R.id.fragment_container, loginFragment);
            transaction.addToBackStack(null); 
            transaction.commit();
            getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);  
            break;

...

我也打过电话setSoftInputMode从片段的onCreate内还没有工作过。 我以为这是一个时机问题,我试图与handler.postDelayed,并没有擦出火花。它看起来是这样的:

I have also tried calling setSoftInputMode from within the fragment's onCreate and that has not worked as well. Thinking it was a timing issue I tried it with handler.postDelayed and that didn't work either. It looked like this:

onResume...    
Handler handler = new Handler();
            Runnable runnable = new Runnable() {

                @Override
                public void run() {
                    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);                
                }
            };

            handler.postDelayed(runnable, 1000);

任何帮助将AP preciated。 谢谢。

Any help will be appreciated. Thanks.

推荐答案

在你的onResume你可以这样做:

On your onResume you can do this:

EditText someEditText = (EditText)getActivity().findViewById(R.id.someEditText);
someEditText.requestFocus(); 
InputMethodManager mgr =      (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(someEditText, InputMethodManager.SHOW_IMPLICIT);

这篇关于SoftKeyboard不显示新显示片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆