自定义TabHost的按钮行为

时间:2013-07-02 05:51:21

标签: android tabs dialog android-tabhost

我目前正在处理包含四个标签按钮的tabbar的应用程序。其中一个标签按钮是“信息”标签。 The information tab shows the information dialog containing detail info regarding to the activity.

Required :信息标签的行为是动态的,它会向不同的活动显示不同的信息详细信息。

有可能吗?怎么做到这一点?或任何其他解决方案。

另一点: Is it possible to show the tab bar for entire application?

提前致谢

1 个答案:

答案 0 :(得分:0)

看你的代码就像

TabHost tabHost = getTabHost();
    // Tab for Photos
TabSpec photospec = tabHost.newTabSpec("Photos");
    // setting Title and Icon for the Tab
    photospec.setIndicator("Photos", getResources().getDrawable(R.drawable.icon_photos_tab));
    Intent photosIntent = new Intent(this, PhotosActivity.class);
    photospec.setContent(photosIntent);


    // Adding all TabSpec to TabHost
    tabHost.addTab(photospec); // Adding photos tab
    tabHost.addTab(songspec); // Adding songs tab
    tabHost.addTab(videospec); // Adding videos tab

您需要处理标签的事件如下

tabHost.getChildAt(1).setOnTouchListener(new OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        int action = event.getAction();

        if(action == MotionEvent.ACTION_UP)
        {
            //Something to do

            return true; // do this if you dont want the tab to change
        }
        return false;
    }
});