如何TabHostFragment自定义 tab键
1个回答
2015-03-26
展开全部
1 获得 tabHostFragment:
ActionBarActivity activity2 = (ActionBarActivity) activity;
mTabHost = new FragmentTabHost(activity2);
mTabHost .setup(getActivity(),getChildFragmentManager(),R.id. content_frame );
2 加入系统默认的indicator
mTabHost .addTab( mTabHost .newTabSpec( "tour" ).setIndicator( "巡视" ), TourFragmentTab . class , null );
3 加入自定义的indicator
indicator = getIndicatorView( "任务" , R.layout. tab_custom );
mTabHost .addTab( mTabHost .newTabSpec( "task" ).setIndicator( indicator ),TaskFragment. class , null );
4 上面用到的getIndicatorView方法如下:
private View indicator = null ;
public View getIndicatorView(String name, int layoutId) {
View v = getActivity().getLayoutInflater().inflate(layoutId, null );
TextView tv = (TextView) v.findViewById(R.id. tabText );
return v;
ActionBarActivity activity2 = (ActionBarActivity) activity;
mTabHost = new FragmentTabHost(activity2);
mTabHost .setup(getActivity(),getChildFragmentManager(),R.id. content_frame );
2 加入系统默认的indicator
mTabHost .addTab( mTabHost .newTabSpec( "tour" ).setIndicator( "巡视" ), TourFragmentTab . class , null );
3 加入自定义的indicator
indicator = getIndicatorView( "任务" , R.layout. tab_custom );
mTabHost .addTab( mTabHost .newTabSpec( "task" ).setIndicator( indicator ),TaskFragment. class , null );
4 上面用到的getIndicatorView方法如下:
private View indicator = null ;
public View getIndicatorView(String name, int layoutId) {
View v = getActivity().getLayoutInflater().inflate(layoutId, null );
TextView tv = (TextView) v.findViewById(R.id. tabText );
return v;
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询