에 대한 감사를 나를 도와.
을 당신은 지원 라이브러리에서 사용할 수있는 FragmentTabHost 클래스를 사용할 필요가 android.support.v4.app
FragmentTabHost를 사용하는 클래스 :
public class SampleTabFragment extends Fragment {
private FragmentTabHost mTabHost;
public static View view;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// fragment not when container null
if (container == null) {
return null;
}
// inflate view from layout
view = (LinearLayout) inflater.inflate(R.layout.offer_tabs, container, false);
// Setting Up the TabHost
mTabHost = (FragmentTabHost) view.findViewById(android.R.id.tabhost);
mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.offer_realtabcontent);
// For adding a tab divider image
mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);
// For Setting up the Tabs with their respective labels
mTabHost.addTab(mTabHost.newTabSpec("info").setIndicator(createTabView
(mTabHost.getContext(), "INFO")), DetailedOfferFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("location").setIndicator(createTabView
(mTabHost.getContext(), "LOCATION")), LocationFragment.class, null);
setRetainInstance(true);
return view;
}
/***** Method for Custom TextView for Tabs *****/
private static View createTabView(final Context context, final String text) {
View view = LayoutInflater.from(context).inflate(R.layout.tabs_text_bg, null);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
tv.setText(text);
return view;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#6D6C6C"
android:orientation="vertical" >
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal" />
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#696969" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
<FrameLayout
android:id="@+id/offer_realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
offer_tabs.xml 탭을 사용하는 레이아웃