0

私はタブバーを使用する Android アプリに取り組んでおり、TabGroupActivity を使用してインテントをナビゲートしています。

    Intent homeIntent = new Intent().setClass(this, SomeActivity.class);
    homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startChildActivity("SomeActivity", homeIntent);

タブバーのホームアイコンをクリックした場所からホームアクティビティをリダイレクトしたい。

4

1 に答える 1

0

TabActivity クラスで、タブを設定するときに OnTouchListener を各タブ ビューに設定し、

view.setOnTouchListener(this);
intent = new Intent().setClass(this, HomeActivity.class);
spec = tabHost.newTabSpec("home").setIndicator(view).setContent(intent);
tabHost.addTab(spec);

TabActivity クラス呼び出し onTouch メソッド

@Override
public boolean onTouch(View view, MotionEvent event) {
    // use getTabHost().getCurrentTabView to decide if the current tab is
    // touched again
    if (event.getAction() == MotionEvent.ACTION_DOWN
            && view.equals(getTabHost().getCurrentTabView())) {
        // use getTabHost().getCurrentView() to get a handle to the view
        // which is displayed in the tab - and to get this views context
        if(getTabHost().getCurrentTabTag().equals("home")) {
            // do what ever you want when tab home icon
        }
    }
    return false;
}
于 2014-02-11T10:08:59.607 に答える