在设置选项卡时,在您的 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;
}