我想更改TabLayout
中状态栏的颜色,但是出现错误?
有错误的代码的屏幕快照 http://s3.picofile.com/file/8370099418/Screenshot_from_2019_08_20_14_57_39.jpg
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
if (tab.getPosition() == 0) {
toolbar.setBackgroundColor(ContextCompat.getColor(MainActivity.this, R.color.colorPrimary));
tabLayout.setBackgroundColor(ContextCompat.getColor(MainActivity.this, R.color.colorPrimary));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().getStatusBarColor(ContextCompat.getColor(MainActivity.this , R.color.colorPrimaryDark));
}
} else if (tab.getPosition() == 1) {
toolbar.setBackgroundColor(ContextCompat.getColor(MainActivity.this, R.color.Yellow));
tabLayout.setBackgroundColor(ContextCompat.getColor(MainActivity.this, R.color.Yellow));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().getStatusBarColor(ContextCompat.getColor(MainActivity.this, R.color.YellowDark));
}
}
}
答案 0 :(得分:0)
我想你必须使用
tabLayout.setStatusBarColor(ContextCompat.getColor(MainActivity.this,R.color.YellowDark))