将选项卡添加到MTAB时出现自定义TabLayout android错误

将选项卡添加到MTAB时出现自定义TabLayout android错误,android,android-tablayout,Android,Android Tablayout,我用我的自定义tablayout视图为tablayout android定制字体,但它使我在MTAB上崩溃;我的代码有什么问题 @Override public void addTab(@NonNull Tab tab, int position, boolean setSelected) { MyTextView myTextView = (MyTextView) View.inflate(getContext(), R.layout.tab_item_template, nu

我用我的自定义tablayout视图为tablayout android定制字体,但它使我在MTAB上崩溃;我的代码有什么问题

@Override
public void addTab(@NonNull Tab tab, int position, boolean setSelected) {
    MyTextView myTextView = (MyTextView)
    View.inflate(getContext(), R.layout.tab_item_template, null);
    myTextView.setText(tab.getText());
    tab.setCustomView(myTextView);

    mTabs.add(position, tab);
    super.addTab(tab, position, setSelected);
}
错误是

java.lang.IndexOutOfBoundsException: Invalid index 10, size is 0

尝试在选项卡布局中设置自定义选项卡

TextView tabOne = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
tabOne.setText("ONE");
tabOne.setTextColor(ContextCompat.getColor(this,R.color.colorAccent));
tabOne.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_tab_favourite, 0, 0);// if you want to set icon on that tab
tabLayout.getTabAt(0).setCustomView(tabOne);

未修复MTAB上的错误。添加(位置,选项卡);当我评论它的时候。tablayout工作正常,但我不能更改文本的颜色,其他一切都不依赖于TextView,我说,当我想将tab添加到ArrayList时,ArrayList为空且索引10超出范围会出错