In this link : How do I apply a style programmatically?
Kevin Grant gave a explaination to this question my problem with his code is the context part. To be precise
if another one using TabLayout as in my case i used this snippet
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
tab.setCustomView(R.layout.chat_tab);
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
tab.setCustomView(null);
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});