Create Custom Tab In Fragmentactivity
i am trying to create custom tab in android , i have create the Tabs into FragmentActivity and FragmentPagerAdapter Here is the code of but i really don't know where do i inflate
Solution 1:
you can specify your layout with tabSpec:
Here you have addTab in your adapter
publicvoidaddTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args)
{
tabSpec.setContent(newDummyTabFactory(mContext));
Stringtag= tabSpec.getTag();
TabInfoinfo=newTabInfo(tag, clss, args);
mTabs.add(info);
mTabHost.addTab(tabSpec);
notifyDataSetChanged();
}
and before you fill you tab with content (ususally in onCreate) you can write your own function
privatestatic View prepareTabView(Context context, String text, int drawable)
{
Viewview= LayoutInflater.from(context).inflate(R.layout.tab_layout, null);
((TextView) view.findViewById(R.id.tabTitle)).setText(text);
((ImageView) view.findViewById(R.id.tabImage)).setImageResource(drawable);
return view;
}
publicstaticvoidaddTab(TabsAdapter adapter, TabHost host, String title, String tag, int drawable, Class cl)
{
TabHost.TabSpecspec= host.newTabSpec(tag);
Viewview= prepareTabView(host.getContext(), title, drawable);
spec.setIndicator(view);
adapter.addTab(spec, cl,null);
}
and now you can populate your tabHost with your own addTab, that uses addTab in adapter:
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
mTabHost.setup();
mViewPager = (ViewPager) findViewById(R.id.pager);
mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager, getSupportFragmentManager());
addTab(mTabsAdapter, mTabHost, getString(R.string.title1), CONST, R.drawable.tab_drawable1, Fragment1.class);
addTab(mTabsAdapter, mTabHost, getString(R.string.title1), CONST2, R.drawable.tab_formula_image_selector, Fragment2.class);
in this example you have R.layout.tab_layout with drawable, background, text and etc... :
R.layout.tab_layout:
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:gravity="top"android:background="@drawable/tabbg"><TextViewandroid:id="@+id/tabTitle"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_marginBottom="30dp"android:text="TextView"android:textColor="@color/tabtextcolor"android:textSize="12sp"android:layout_alignParentBottom="true"/><ImageViewandroid:id="@+id/tabImage"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginBottom="5dp"android:layout_above="@id/tabTitle"android:layout_centerHorizontal="true"/></RelativeLayout>
with this example you will have smth like this:
Post a Comment for "Create Custom Tab In Fragmentactivity"