Android app状态栏与导航栏统一风络方法

直接上代码,一般在开发App时状态栏与导航栏所在的Activity都会统一继承一个类似BaseActivity的基类,只要我们

在基类统一处理好就可以了,主要代码实现如下:

public abstract class BaseActivity extends FragmentActivity {
    public FragmentManager mFragmentManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //状态栏颜色修改
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setTranslucentStatus(true);
            SystemBarTintManager tintManager = new SystemBarTintManager(this);
            tintManager.setStatusBarTintEnabled(true);
            tintManager.setStatusBarTintResource(R.color.all_title_bgcolor);//通知栏所需颜色
        }
    }

    @TargetApi(19)
    private void setTranslucentStatus(boolean on) {
        Window win = getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if (on) {
            winParams.flags |= bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }
}


注:all_title_bgcolor的值别忘了在相应的xml定义好

xml version="1.0" encoding="utf-8"?>

    name="all_title_textcolor">#ffffff
    name="all_title_bgcolor">#bf0711


只要基类中导入相关类,添加载以上代码即可


你可能感兴趣的:(android移动开发)