0

私のアプリケーションは、ネストされたアクティビティを含むTabHostとActivityGroupで構成されています。ActivityGroupのアクティビティが作成または再開されると、ソフトキーボードがすぐに表示されます。EditTextをクリックするだけで表示される必要があります。私のActivityGroupクラス:

public class LoginTabGroup  extends ActivityGroup {

private ArrayList<String> mIdList;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (mIdList == null) mIdList = new ArrayList<String>();
    }

/**
* This is called when a child activity of this one calls its finish method.
* This implementation calls {@link LocalActivityManager#destroyActivity} on the child activity
* and starts the previous activity.
* If the last child activity just called finish(),this activity (the parent),
* calls finish to finish the entire group.
*/
@Override
public void finishFromChild(Activity child) {
LocalActivityManager manager = getLocalActivityManager();
int index = mIdList.size()-1;

if (index < 1) {
finish();
return;
}

manager.destroyActivity(mIdList.get(index), true);
mIdList.remove(index);
index--;
String lastId = mIdList.get(index);
Intent lastIntent = manager.getActivity(lastId).getIntent();

Window newWindow = manager.startActivity(lastId, lastIntent);
newWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Log.i("ActivityGroup","finishFromChild method");
setContentView(newWindow.getDecorView());
}

/**
* Starts an Activity as a child Activity to this.
* @param Id Unique identifier of the activity to be started.
* @param intent The Intent describing the activity to be started.
* @throws android.content.ActivityNotFoundException.
*/
public void startChildActivity(String Id, Intent intent) 
{
    Window window = getLocalActivityManager().startActivity(Id,intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
    window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
    Log.i("ActivityGroup","startActivity method");
    if (window != null) {
    mIdList.add(Id);
    setContentView(window.getDecorView());
    }
}

/**
* The primary purpose is to prevent systems before android.os.Build.VERSION_CODES.ECLAIR
* from calling their default KeyEvent.KEYCODE_BACK during onKeyDown.
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
    //preventing default implementation previous to android.os.Build.VERSION_CODES.ECLAIR
    return true;
    }
    return super.onKeyDown(keyCode, event);
}

/**
* Overrides the default implementation for KeyEvent.KEYCODE_BACK
* so that all systems call onBackPressed().
*/
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
    onBackPressed();
    return true;
    }
    return super.onKeyUp(keyCode, event);
}

/**
* If a Child Activity handles KeyEvent.KEYCODE_BACK.
* Simply override and add this method.
*/
    @Override
    public void onBackPressed () {
    int length = mIdList.size();
    if ( length > 1) {
    Activity current = getLocalActivityManager().getActivity(mIdList.get(length-1));
    current.finish();
    }
}
}

私はこのようにしようとしましたnewWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

新しいウィンドウの作成時に、しかしそれは役に立ちませんでした。のようなアプローチ

 InputMethodManager imm = (InputMethodManager)getSystemService(
              Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

ネストされたアクティビティでは正しく機能しますが、アクティビティの作成または再開時にキーボードが表示され、すぐに非表示になります。キーボードが点滅しているので、良い解決策ではないと思います。AndroidManifestにも追加してみました

 android:windowSoftInputMode="stateAlwaysHidden" 
         android:configChanges="keyboardHidden|orientation"

ネストされたアクティビティ、ActivityGroupsの両方。しかし、結果は同じままです。どうすればこれを解決できますか?

4

3 に答える 3

0

これは、レイアウト内のエディットテキストがフォーカス可能な要素であり、他の要素が要求していない場合は起動時にフォーカスを要求するために発生します。解決策は簡単です。すべてのレイアウトファイルで、コンテナレイアウトでfocusableおよびfocusableInTouchModeをtrueに設定します。これにより、最初にフォーカスが要求され、編集テキストはフォーカスされなくなります。次に、暗黙的に非表示にしているものを削除できます)

android:focusable="true"
android:focusableInTouchMode="true"
于 2013-02-22T09:32:36.843 に答える
0

私はこの問題にハックを使用しました。ActivityGroupのクラスと子アクティビティの両方に

        InputMethodManager imm = (InputMethodManager)getSystemService(
                  Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); 

onCreate()およびonResume()メソッドの前。知っている人がもっと効果的な解決策を教えてくれたらありがたいです。

于 2013-03-15T13:10:12.197 に答える
0

ActivityGroupを使用することは、本当に悪くて遅い解決策です。タブ内のネストされたフラグメントでFragmentActivitiesを使用することにしました。それにもかかわらず、アクティビティが開始されたときにソフトキーボードが表示されることがありました。画像のないタブの1つにテキストを中央に設定しました。ソフトキーボード表示と呼ばれていると思います。私の修正(TabActivityクラス内):

 final View view = tabHost.getTabWidget().getChildTabViewAt(1);
       if ( view != null ) {
         //  view.getLayoutParams().height *= 0.66;
           InputMethodManager imm2 = (InputMethodManager)getSystemService(
                  Context.INPUT_METHOD_SERVICE);
           imm2.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
           //  get title text view
           final View textView = view.findViewById(android.R.id.title);
           if ( textView instanceof TextView ) {
               // just in case check the type

               // center text
               ((TextView) textView).setGravity(Gravity.CENTER);
               // wrap text
               ((TextView) textView).setSingleLine(false);
               // explicitly set layout parameters
               textView.getLayoutParams().height = ViewGroup.LayoutParams.FILL_PARENT;
               textView.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
           }
       }
于 2013-04-22T13:02:10.560 に答える