ekatz
ekatz

Reputation: 973

Android: in TabWidget, is there a way to get the view containing the tabs?

Hi all I'm trying to write a tab activity in which each of the tabs has a custom view for the indicator. The view is inflated like so:

LayoutInflater inflater = (LayoutInflater)
            context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
        specIndicatorView = inflater.inflate(R.layout.tab_indicator, null);

        indicatorIv = (ImageView)specIndicatorView.findViewById(R.id.indicatorImage);
        indicatorTv = (TextView)specIndicatorView.findViewById(R.id.indicatorText);

        indicatorIv.setImageDrawable(context.getResources().getDrawable(indicatorImageRes));
        indicatorTv.setText(indicatorTextRes);

The problem is that the layout parameters that are defined in the child view do not affect it and that is because I don't know how to pass in the parent view to the inflate method.

All I'm trying to do is have an image and some text where the image is aligned to the top and the text is aligned to the bottom of the indicator view but I also need some little tweaks that require me to use this indicator strategy. I've looked at the source of the entire tab mechanism and could not figure out how to get the parent view, do you know how to do it? do you have a better way to achieve what I need?

Thanks

Upvotes: 0

Views: 3678

Answers (2)

Yoni Samlan
Yoni Samlan

Reputation: 38075

You said you looked through all the code for tabs; what was wrong with just calling getTabWidget() in your activity?

Upvotes: 2

jakebasile
jakebasile

Reputation: 8132

Are you trying to access the TabHost from within one of the tab activities? If so, you should be able to get to the TabHost via getParent() from the child activity.

Upvotes: 0

Related Questions