您的位置:首页 > 移动开发 > Android开发

android 4.4状态栏沉浸

2015-09-12 19:05 393 查看
找了半天代码发现好多帖子好乱

最后在github发现开源库:SystemBarTint

直接使用。即可


Usage

You must first enable translucency in your Activity - either by using or inheriting from one of the various
*.TranslucentDecor
themes,
by setting the
android:windowTranslucentNavigation
or
android:windowTranslucentStatus
theme
attributes to
true
or by applying the
FLAG_TRANSLUCENT_N***IGATION
or
FLAG_TRANSLUCENT_STATUS
flags
to your Activity window in code.

If translucency is not enabled or your app is running on a platform version earlier than API 19, the system UI will appear as normal. You should not enable tinting when using fullscreen or immersive window modes. You can safely use this library on Android versions
back to API 10.

To enable the tint:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // create our manager instance after the content view is set
    SystemBarTintManager tintManager = new SystemBarTintManager(this);
    // enable status bar tint
    tintManager.setStatusBarTintEnabled(true);
    // enable navigation bar tint
    tintManager.setNavigationBarTintEnabled(true);
}


To provide custom tint color values or drawables:

// set a custom tint color for all system bars
tintManager.setTintColor(Color.parseColor("#99000FF"));
// set a custom navigation bar resource
tintManager.setNavigationBarTintResource(R.drawable.my_tint);
// set a custom status bar drawable
tintManager.setStatusBarTintDrawable(MyDrawable);



SystemBarConfig

Developers should not need to concern themselves with the size or positioning of the system UI. Use
android:fitsSystemWindows="true"
in
conjunction with
android:clipToPadding="false"
to achieve the optimal layout for full bleed content screens that need to be
padded within the system UI bounds. However, certain elements like the
GoogleMap
provided by Google Play Services may force
you to determine the pixel insets for the system bars in order to provide the appropriate layout effect.

Use the
SystemBarConfig
class provided by
SystemBarTintManager
to
access those inset values:

SystemBarConfig config = tintManager.getConfig();
map.setPadding(0, config.getPixelInsetTop(), config.getPixelInsetRight(), config.getPixelInsetBottom());



Setup

Download and include the JAR in
your project, or add the dependency in your
build.gradle
:

dependencies {
    compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: