在调用显示ProgressDialog的新Activity后隐藏键盘

Ven*_*r85 6 android dialog progressdialog android-input-method android-activity

我在屏幕键盘上遇到了麻烦.我有一个EditText显示键盘的活动,以及一个进入第二个活动的按钮.第二个活动显示了ProgressDialogonCreate(),做了什么,并解散了ProgressDialog.问题是ProgressDialog显示时,键盘也是如此.

我希望键盘在创建之前消失ProgressDialog.我搜索了StackOverflow和其他网站,但似乎没有任何东西可以用于这个特定的场景.

我附上两张照片供你参考:

http://i45.tinypic.com/2rzq7b6.png http://i45.tinypic.com/34ret1z.png

这是第一个活动的代码:

public class FirstActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        findViewById(R.id.button1).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
                startActivity(intent);
            }
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

这是第二个活动的代码:

public class SecondActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second);

        // TODO: hide keyboard here

        final ProgressDialog dialog = ProgressDialog.show(this, "", "Please wait...", true, false, null);

        // in real code, here there is an AsyncTask doing stuff...
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                dialog.dismiss();
            }
        }, 5000);
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢

Ven*_*r85 20

使用phalt发布的技术变体解决:

InputMethodManager im = (InputMethodManager) this.getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
Run Code Online (Sandbox Code Playgroud)

此代码在onCreate/ onStart/ 期间正常工作onResume,因为不依赖于焦点视图来获取窗口令牌.

  • 这不适合我.把它放在onCreate上. (2认同)

Kri*_*har 10

将此代码写入manifest.xml文件中以获取"SecondActivity"活动.

<activity name="EditContactActivity"
    android:windowSoftInputMode="stateAlwaysHidden">
    ...
</activity>
Run Code Online (Sandbox Code Playgroud)