2

android的twitter应用程序具有自定义viewpager选项卡,这是如何完成的?文本位于每个相应选项卡中有新内容时出现的小型中心dotthat上方。android twitter应用程序,自定义viewpager选项卡如何

我知道如何使用ACTION BAR选项卡执行此操作,但操作栏选项卡的问题是在横向模式下它们移至实际操作栏。 Viewpager选项卡不这样做。

我已经处理了一些Viewpager字幕库,但我不清楚这是如何做到

回答

3

答案之一是使用第三方库像PagerSlidingTabStrip,或者一个叉,其允许将任意绘制在标签

+0

看看我的家乡答案:-) – Zinc

1

你可以设置自己的意见,每一个标签,你应该创建一个布局XML(custom_tab_icon.xml)与一个TextView和TextView的下方的蓝色圆点

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<TextView 
    android:id="@+id/tab_name" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="TITLE"/> 
<ImageView 
    android:id="@+id/dot" 
    android:layout_width="5dp" 
    android:layout_height="5dp" 
    android:layout_below="@id/tab_name" 
    android:layout_centerHorizontal="true" 
    android:background="@drawable/notifiercircle" 
    android:visibility="visible"/> 

然后,每次更改选项卡,调用此方法refreshTabIcon:

private void refreshTabIcons() { 
    for (int i = 0; i < tabLayout.getTabCount(); i++) { 
     TabLayout.Tab tab = tabLayout.getTabAt(i); 
     tab.setCustomView(null); //if view is not first nullyfied, it's added to the previous one, not replaced 
     tab.setCustomView(R.layout.custom_tab_icon); 
     ImageView dot = ((ImageView) tab.getCustomView().findViewById(R.id.dot)); 
     if (viewPagerAdapter.getItem(viewPager.getCurrentItem()) == viewPagerAdapter.getItem(i)) {//This if determines if this is the selected tab 
      dot.setVisibility(View.VISIBLE); 
     } else { 
      dot.setVisibility(View.INVISIBLE); 
     } 
     ((TextView) tab.getCustomView().findViewById(R.id.tab_name)).setText("tab title"); 
    } 
}