为了账号安全,请及时绑定邮箱和手机立即绑定

关于在Fragment中使用ViewPager和TabPageIndicator

我在一个Fragment中使用ViewPager和TabPageIndicator得到的Tab没有下划线和无指示选择了哪个Tab,请问一下怎么解决?


正在回答

3 回答

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>

0 回复 有任何疑惑可以回复我~

同求啊

0 回复 有任何疑惑可以回复我~

兄弟,你这个问题解决没有,解决了给我说下呢,我也遇到这个问题了.

0 回复 有任何疑惑可以回复我~
#1

局外人_0002 提问者

设置Style
2015-08-17 回复 有任何疑惑可以回复我~
#2

慕码人1073915 回复 局外人_0002 提问者

怎么做,详细说下
2015-12-07 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
多种多样的App主界面Tab实现方法
  • 参与学习       48915    人
  • 解答问题       204    个

本课程就将讲解迄今为止最流行的4种实现Tab的方法

进入课程

关于在Fragment中使用ViewPager和TabPageIndicator

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号