Android 修改状态栏的方法
public class BaseActivity extends AppCompatActivity {
public static final int THIS_STATES_BAR_COLOR = R.color.vx_top_black;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_base);
setThisStatusBarColor(THIS_STATES_BAR_COLOR);
}
public void setThisStatusBarColor(final int resId) {
getWindow().getDecorView().addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
int identifier = getResources().getIdentifier("statusBarBackground", "id", "android");
View statusBarView = getWindow().findViewById(identifier);
statusBarView.setBackgroundResource(resId);
getWindow().getDecorView().removeOnLayoutChangeListener(this);
}
});
}
}