2017-03-15 18 views
-2

ViewPager 및 ViewPagerIndicator 라이브러리를 사용하고 있습니다. TabPagerIndicator를 사용했는데 한 페이지에서 다른 페이지로 이동하여 각 페이지의 제목을 올바르게 볼 수는 있지만 문제는 있습니다. 어떤 탭이 활성 상태이고 어떤 상태인지 알 수 없습니다. 스크린 샷에서 라이브러리 코드와 함께 사용할 수 있습니다. 파란색 선을 선택한 탭의 제목 아래에 그려진 볼 수 있지만 내 응용 프로그램에서 전혀 그 줄을 볼 수 없습니다. 일부 리소스를 변경하는 코드를 시도했지만 아무 것도 얻지 못했습니다. 도움이 될 것입니다. 내 XML :android viewpagerindicator tabpageIndicator 탭이 표시되지 않습니다.

<?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

tabIndicator 등록 정보를 사용자 정의 ... 그리고 회신에 대한 코드 – rafsanahmad007

+0

들으 수, 난 내 코드 – user173488

+0

를 왜 추가 네이티브'android.support.design.widget.TabLayout'을 사용하고 있습니까? – rafsanahmad007

답변

0

는 XML로이 시도 :

사전

편집에 들으 고해상도/값/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> 

당신이 당신의 XML을 게시