Sofia的使用

现在我们的项目中经常需要适配StatusBarNavigationBar,我们需要写很多的代码来进行适配,已完成所需功能。现在来介绍一个第三方Sofia来进行适配,大大的简化了我们代码的编写。下面来看具体使用。
首先,Sofia的引入,添加依赖

compile 'com.yanzhenjie:sofia:1.0.5'

其次,提供的方法列表如下:

// 状态栏深色字体。
Bar statusBarDarkFont();

// 状态栏浅色字体。
Bar statusBarLightFont();

// 状态栏背景色。
Bar statusBarBackground(int statusBarColor);

// 状态栏背景 Drawable。
Bar statusBarBackground(Drawable drawable);

// 状态栏背景透明度。
Bar statusBarBackgroundAlpha(int alpha);

// 导航栏背景色。
Bar navigationBarBackground(int navigationBarColor);

// 导航栏背景 Drawable。
Bar navigationBarBackground(Drawable drawable);

// 导航栏背景透明度。
Bar navigationBarBackgroundAlpha(int alpha);

// 内容入侵状态栏。
Bar invasionStatusBar();

// 内容入侵导航栏。
Bar invasionNavigationBar();

// 让某一个 View 考虑状态栏的高度,显示在适当的位置,接受 ViewId。
Bar fitsStatusBarView(int viewId);

// 让某一个 View 考虑状态栏的高度,显示在适当的位置,接受 View。
Bar fitsStatusBarView(View view);

// 让某一个 View 考虑导航栏的高度,显示在适当的位置,接受 ViewId。
Bar fitsNavigationBarView(View view);

// 让某一个 View 考虑导航栏的高度,显示在适当的位置,接受 View。
Bar fitsNavigationBarView(View view);
注意:Sofia.with(Activity)后返回一个Bar接口实例,这里的方法结合具体的场景调用一个或者几个方法,也可以一个都不调用

最后,一些场景的方法使用
1,如图


image.png

代码为:

Sofia.with(this)
                .statusBarLightFont()//状态栏浅色字体
                .invasionStatusBar()//内容入侵状态栏
                .navigationBarBackground(ContextCompat.getColor(this, R.color.toast_bg))//导航栏背景色
                .statusBarBackground(Color.TRANSPARENT);//状态栏背景色

2,如图,改变状态栏和导航栏背景


image.png

image.png

代码为:

Sofia.with(this)
                .statusBarBackground(ContextCompat.getDrawable(this, R.drawable.banner))//设置状态栏背景Drawable
                .navigationBarBackground(ContextCompat.getDrawable(this, R.drawable.icon_01));//设置导航栏背景Drawable

是不是很简单呢...

参考:http://p.codekk.com/detail/Android/yanzhenjie/Sofia

你可能感兴趣的:(Sofia的使用)