setOnTabSelectedListener在附加选项卡设置明智状态栏,工具栏和tablayout像这样的色彩......
tablayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
if(tab.getPosition()==0){
toolbar.setBackgroundColor(ContextCompat.getColor(HomeScreen.this,
android.R.color.darker_gray));
tablayout.setBackgroundColor(ContextCompat.getColor(HomeScreen.this,
android.R.color.darker_gray));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(ContextCompat.getColor(HomeScreen.this,
android.R.color.darker_gray));
}
}
else if(tab.getPosition()==1){
toolbar.setBackgroundColor(ContextCompat.getColor(HomeScreen.this,
android.R.color.holo_blue_dark));
tablayout.setBackgroundColor(ContextCompat.getColor(HomeScreen.this,
android.R.color.holo_blue_dark));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(ContextCompat.getColor(HomeScreen.this,
android.R.color.holo_blue_dark));
}
}
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
我希望这是有帮助的...