Android 使用滑动布局的自定义选项卡?

Android 使用滑动布局的自定义选项卡?,android,android-custom-view,android-tabs,pagerslidingtabstrip,Android,Android Custom View,Android Tabs,Pagerslidingtabstrip,这是我的密码 public class ViewPagerAdapter extends FragmentStatePagerAdapter { private static int[] ICONS = new int[] { R.drawable.image_back_icon, R.drawable.image_category_icon, R.drawable.activated, R.drawable.image_cart

这是我的密码

public class ViewPagerAdapter extends FragmentStatePagerAdapter {

private static int[] ICONS = new int[] {
        R.drawable.image_back_icon,
        R.drawable.image_category_icon,
        R.drawable.activated,
        R.drawable.image_cart_icon,
        R.drawable.image_profile_icon
};

// Build a Constructor and assign the passed Values to appropriate values in the class
public ViewPagerAdapter(FragmentManager fm,CharSequence mTitles[], int mNumbOfTabsumb) {
    super(fm);

}

//This method return the fragment for the every position in the View Pager
@Override
public Fragment getItem(int position) {

    switch (position) {
        case 0: Tab1 tab1 = new Tab1();
                return tab1;
        case 1: Tab2 tab2 = new Tab2();
            return tab2;
        case 2: Tab3 tab3 = new Tab3();
            return tab3;
        case 3: Tab4 tab4 = new Tab4();
            return tab4;
        case 4: Tab5 tab5 = new Tab5();
            return tab5;
        default: return null;
    }
}

// This method return the titles for the Tabs in the Tab Strip

@Override
public CharSequence getPageTitle(int position) {
    return null;
}


// This method return the Number of tabs for the tabs Strip

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

public int getDrawableId(int position) {
    return ICONS[position];
}
}

public class MainActivity extends AppCompatActivity {

//Toolbar toolbar;
ViewPager pager;
ViewPagerAdapter adapter;
SlidingTabLayout tabs;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    adapter =  new ViewPagerAdapter(getSupportFragmentManager(),Titles,Numboftabs);

    pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(adapter);

    tabs = (SlidingTabLayout) findViewById(R.id.tabs);
    tabs.setDistributeEvenly(true); 
    tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
       @Override
       public int getIndicatorColor(int position) {
            return getResources().getColor(R.color.primary);
        }
    });

    // Setting the ViewPager For the SlidingTabsLayout
    tabs.setViewPager(pager);



}

}
我一直到图1,我想达到图2所示的效果

我希望它们能够响应,但效果如图2所示

我试过使用一个定制的绘图工具,但似乎不起作用。如何使图标变为活动颜色以及使搜索图标具有背景颜色

我应该如何实现这一点,使其在所有设备和屏幕尺寸下都能工作


谢谢。

也许你忘了打电话了

slidingTabLayout.setDistributeEvenly(true);
slidingTabLayout.setViewPager(viewPager);

问题是下划线不跟随图标,也不更改选项卡?我说得对吗。不要使用
滑动布局
。2.使用新的设计支持库,请参见这里的示例:我正在调用它,代码运行良好,我的问题是如何使其与第二张图片类似。也许这对你有帮助