关于在Fragment中使用ViewPager和TabPageIndicator
我在一个Fragment中使用ViewPager和TabPageIndicator得到的Tab没有下划线和无指示选择了哪个Tab,请问一下怎么解决?
我在一个Fragment中使用ViewPager和TabPageIndicator得到的Tab没有下划线和无指示选择了哪个Tab,请问一下怎么解决?
2015-06-16
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view=super.onCreateView(inflater,container,savedInstanceState);
LinearLayout ll = (LinearLayout) view.findViewById(R.id.ll_tab_page);
//给 Fragment设置样式
final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.Theme_PageIndicatorDefaults);
LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
View view1 = localInflater.inflate(R.layout.tabpageindicator, container, false);
ll.addView(view1);
viewPager = (ViewPager) view.findViewById(R.id.ad_vPager);
indicator = (TabPageIndicator) view.findViewById(R.id.ad_indicator);
getADCategories = networking.get(this, UrlConstant.SYS_AD_CATEGORY, null, AdCategory.class);
adapter = new AdViewPagerAdapter(getChildFragmentManager(), categories);
viewPager.setAdapter(adapter);
indicator.setViewPager(viewPager);
indicator.setFillViewport(true);
return view;
}
@Override
public void onDetach() {
super.onDetach();
try {
//参数是固定写法
Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
childFragmentManager.setAccessible(true);
childFragmentManager.set(this, null);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
fragment xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#EDEDED"
android:orientation="vertical">
<include layout="@layout/merge_titlebar" />
<LinearLayout
android:id="@+id/ll_tab_page"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
tabpage xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<com.viewpagerindicator.TabPageIndicator
android:id="@+id/ad_indicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/white" />
<android.support.v4.view.ViewPager
android:id="@+id/ad_vPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:flipInterval="30"
android:persistentDrawingCache="animation" />
</LinearLayout>
举报