wuf*_*foo 5 android android-activity
我有一个在TabHost中运行的Activity(扩展Activity).我从用户操作启动Android电子邮件客户端.如果我点击电子邮件客户端中的"放弃"按钮,电子邮件客户端将退出,但屏幕上的键盘仍然可见.
我的应用程序上没有EditTexts,因此不确定为什么键盘会保持运行状态.我已经尝试了几次迭代,如何在完成活动后移除键盘?但是没有运气.有什么想法吗?
代码示例
package com.test.launchmail;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;
public class myEmail extends Activity
{
private final String TAG = "** Email **";
public static void send (Context ctx, String addy, String subject, String body)
{
// check to make sure the entry has a phone number
try
{
// use the builtin chooser for users mail app
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String [] {addy});
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
ctx.startActivity (Intent.createChooser(sendIntent, "Send via which Application?"));
}
catch (Exception e)
{
Toast.makeText (ctx, "No activity was found to handle this action",Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onPostResume()
{
// This executes, but keyboard still visible.
Log.d ("myEmail", "hiding");
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow (mainApp.tabHost.getCurrentTabView ().getApplicationWindowToken (),imm.HIDE_IMPLICIT_ONLY);
super.onResume ();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2258 次 |
| 最近记录: |