简体   繁体   English

Android标签栏不响应

[英]Android tabbar doesn't respond

I'm working on android app which uses tabbar, navigating through intents using TabGroupActivity, 我正在使用使用Tabbar的android应用程序,使用TabGroupActivity浏览意图,

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

I want to redirect the my home activity from where ever i clicked tabbar home icon. 我想从单击标签栏主页图标的位置重定向我的主页活动。

In your TabActivity class set OnTouchListener to the each tab view when setting the tabs, 设置标签时,在您的TabActivity类中,将OnTouchListener设置为每个标签视图,

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

TabActivity class call onTouch method 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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM