TabLayout +ViewPager 自定义Tab的UI

在使用TabLayout +ViewPager底部按钮时,想要自定义Tab的UI是很麻烦的。
需要在完后TabLayout和ViewPager绑定之后,在TabLayout添加完Tab之后再去遍历tab:

    for (int i = 0; i < mTabLayout.getTabCount(); i++) {
            mTabLayout.getTabAt(i).setCustomView(getTabView(i));
        }


 private View getTabView(int index) {

        View inflate = LayoutInflater.from(this).inflate(R.layout.itemtab, null);
        TextView tabTV = inflate.findViewById(R.id.tab);

        tabTV.setText(tabs[index]);
        Drawable icon = ContextCompat.getDrawable(this, mTabImages[index]);
        tabTV.setCompoundDrawablePadding(3);
        tabTV.setCompoundDrawablesRelativeWithIntrinsicBounds(null, icon, null, null);
        tabTV.setPadding(0, 2, 0, 2);


        return inflate;
    }

你可能感兴趣的:(TabLayout +ViewPager 自定义Tab的UI)