5

編集解決しました。以下に別途掲載された回答

組み込みのIntent.ACTION_SEND"chooser"を起動して、ユーザーがアプリケーションからメッセージを送信する方法を選択できるようにします。正常に動作しますが、起動した電子メールプログラムで[破棄]をクリックすると、画面キーボードが表示されたままアプリケーションに戻ります。imm.hideSoftInputFromWindow(...)のさまざまな呪文で閉じようとしましたが、役に立ちませんでした。これを修正する方法はありますか?

これが、「chooser」を起動し、onActivityResult()でキーボードを閉じようとしている方法です。tabHostは、tabSpecの作成に使用されるtabHostオブジェクトを保持するメインアプリケーション(MainApp)の静的メンバーであることに注意してください。

public class L_Secondary extends ListActivity implements myConst
{   
    @Override
   protected void onCreate (Bundle savedInstanceState)
   {
     super.onCreate (savedInstanceState);
     setContentView(R.layout.l_people_secondary);

     // instantiate the custom array adapter class and pass it some info to build a ListView with. 
     ListView lv = getListView ();
     lv.setOnItemClickListener (oicl);
     A_secondary da = new A_secondary (this, android.R.layout.simple_list_item_single_choice, mPiecesArray, mPartsArray);

     setListAdapter (da);
   }

   ...  


   // after launching the email client, the keyboard stays visible 
   // over the Listview. Currently the keyboard gets forced to close 
   // in getView() of the ArrayAdapter class da, in onCreate() above                
   public void launchEmail () 
   {
    try
    {
     // use the builtin chooser for users mail app
     Intent sendIntent = new Intent(Intent.ACTION_SEND, Uri.fromParts ("mailto", "root@localhost", null));
     sendIntent.setType("text/plain");    

     sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "msg_subject");
     sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, "msg_body");

     startActivityForResult (Intent.createChooser(sendIntent, "Send via which Application?"), 0);
    }
    catch (Exception e) 
    {
     Toast.makeText (this, "No activity was found to handle this action",Toast.LENGTH_SHORT).show();
    }
  }

 ...

}
4

4 に答える 4

5

onResume() に追加することで、これがうまくいくことがわかりました

protected void onResume()
{
  Handler h = new Handler();
  h.postDelayed(new Runnable() {
     @Override
     public void run() {
        InputMethodManager keyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        keyboard.hideSoftInputFromWindow(findViewById(android.R.id.content).getWindowToken(), 0);
     }
  }, 500);
}
于 2016-05-11T09:09:31.153 に答える
0

onResume() で hideSoftInputFromWindow メソッドを呼び出すことができると思います

protected void onResume()
{
    InputMethodManager keyboard = (InputMethodManager)
    getSystemService(Context.INPUT_METHOD_SERVICE);
    keyboard.hideSoftInputFromWindow(userInput.getWindowToken(), 0);
}
于 2012-07-17T19:21:02.023 に答える
0

MAIL //ed is EditText のインテントを呼び出す前に、このコードを使用してください

InputMethodManager imm = (InputMethodManager)this.getSystemService(Service.INPUT_METHOD_SERVICE);

キーボードを隠す

imm.hideSoftInputFromWindow(ed.getWindowToken(), 0); 

ショーキーボード用

imm.showSoftInput(ed, 0);

onRestart() メソッドでもこのコードを試してください

また

あなたもこれを試すことができます

<activity android:name=".YourActivity"
          android:windowSoftInputMode="stateHidden"></activity>

ありがとう。

于 2012-07-17T19:16:36.850 に答える
0

L_Secondary クラスでインスタンス化された ArrayAdapter クラスの getView() に渡された Context を使用することになりました。リストがスクロール、タッチ、または移動されるたびに、キーボードが表示されているかどうかを確認し、表示されている場合は閉じるため、これを行うのに最適な場所ではありません。とはいえ、スタートです。ここから、より効率的な配置場所を見つけようとします。

@Override
 public View getView (int position, View convertView, ViewGroup parent)
 {
     View row = convertView;
     Context ctx = parent.getContext ();

     if (row == null)
     {
         LayoutInflater inflater = ((Activity) ctx).getLayoutInflater ();
         row = inflater.inflate (R.layout.li_secondary, parent, false);
     }

     // hide the keyboard when coming back from Email client Intent
     InputMethodManager imm = (InputMethodManager) ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
     if (imm.isActive () == true)
         imm.hideSoftInputFromWindow (MainApp.tabHost.getCurrentTabView ().getApplicationWindowToken (),imm.HIDE_NOT_ALWAYS);
     ...
}
于 2012-07-18T14:22:38.103 に答える