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"); 
    } 
}