2017-03-15 44 views
-2

我正在使用ViewPager和ViewPagerIndicator库,我使用TabPagerIndicator,问题是虽然我可以从一个页面导航到另一个并正确地看到每个页面对应的标题,但是我不能看到哪个选项卡处于活动状态,哪些不是。 在与库代码可用的屏幕截图中,我可以看到在选定选项卡标题下绘制的蓝色线条,但在我的应用程序中,我无法看到该线条。 我试着通过代码改变一些资源,但什么也没有。 任何帮助将不胜感激。 THX提前android viewpagerindicator tabpageIndicator选项卡没有显示/关闭

编辑: 我的xml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.apple.gallerapplication.GalleryActivity" 
    > 
    <com.viewpagerindicator.TabPageIndicator 
     android:id="@+id/indicator" 
     android:padding="10dip" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_alignParentTop="true" 
     android:textColor="@android:color/black" 
     android:foregroundGravity="center" 
     /> 

     /> 
    <android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/indicator"/> 
</RelativeLayout> 

活动代码

public class GalleryActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_gallery); 

     //viewpager 
     ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); 
     viewPager.setAdapter(new CustomPagerAdapter(this)); 


     TabPageIndicator mIndicator = (TabPageIndicator)findViewById(R.id.indicator); 
     mIndicator.setViewPager(viewPager); 


    } 
} 

寻呼机适配器:

public class CustomPagerAdapter extends PagerAdapter implements IconPagerAdapter { 

private Context mContext; 

public CustomPagerAdapter(Context context) { 
    mContext = context; 
} 

@Override 
public Object instantiateItem(ViewGroup collection, int position) { 
    CustomPagerEnum customPagerEnum = CustomPagerEnum.values()[position]; 
    LayoutInflater inflater = LayoutInflater.from(mContext); 
    ViewGroup layout = (ViewGroup) inflater.inflate(customPagerEnum.getLayoutResId(), collection, false); 
    collection.addView(layout); 
    return layout; 
} 

@Override 
public void destroyItem(ViewGroup collection, int position, Object view) { 
    collection.removeView((View) view); 
} 

@Override 
public int getCount() { 
    return CustomPagerEnum.values().length; 
} 

@Override 
public boolean isViewFromObject(View view, Object object) { 
    return view == object; 
} 

@Override 
public CharSequence getPageTitle(int position) { 
    CustomPagerEnum customPagerEnum = CustomPagerEnum.values()[position]; 
    return mContext.getString(customPagerEnum.getTitleResId()); 

} 



@Override 
public int getIconResId(int index) { 
    return 0; 
} 
} 
+1

发表您的xml ...和代码 – rafsanahmad007

+0

THX的回复,我已经加了我的代码 – user173488

+0

为什么不使用本机'android.support.design.widget.TabLayout'? – rafsanahmad007

回答

0

在XML中试试这个:

<!-- use tablayout to display tabs --> 
<android.support.design.widget.TabLayout 
    android:id="@+id/tabLayout" 
    style="@style/AppTabLayout" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:background="@color/your_color" /> 
在res /价值/ styles.xml

<style name="AppTabLayout" parent="Widget.Design.TabLayout"> 
    <item name="tabIndicatorColor">@color/colorAccent</item> //indicator color 
    <item name="tabIndicatorHeight">4dp</item>    //indicator height 
    <item name="tabPaddingStart">6dp</item> 
    <item name="tabPaddingEnd">6dp</item> 
    <item name="tabSelectedTextColor">@color/color_white</item> 
</style> 

在这里你可以自定义tabIndicator性能

相关问题