Since upgrading from 23.1.0 to 23.1.1 of the appcompat library, calling setCustomView() on a TabLayout.Tab throws a NullPointerException.
eg
TabLayout.Tab tab = mTabLayout.newTab();
tab.setCustomView(R.layout.tab_photo_indicator);
mTabLayout.addTab(tab);
Throws a NullPointerException on the second line. The exception points to TabLayout.java:1019 inside the appcompat library, the inflater = line below:
public Tab setCustomView(int resId) {
final TabView tabView = mParent.getTabView(mPosition);
final LayoutInflater inflater = LayoutInflater.from(tabView.getContext());
return setCustomView(inflater.inflate(resId, tabView, false);
}
Downgrading back to 23.1.0 makes it work again, but 23.1.1 fixes a different issue I experience in that version.
Is there something wrong in what I'm doing or is this an issue in the support library?
Adding the tab to the layout before setting the custom view avoids the crash. eg:
TabLayout.Tab tab = mTabLayout.newTab();
mTabLayout.addTab(tab);
tab.setCustomView(R.layout.tab_photo_indicator);
Unfortunately the layout doesn't display exactly as before but I was able to modify the layout to suit.
This issue also precludes creating and adding the tab as a one liner. eg:
mTabLayout.addTab(mTabLayout.newTab().setCustomView(r.layout.tab_photo_indicator));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With