Coder Social home page Coder Social logo

jianfang-kso / translucentbar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kelin-hong/translucentbar

0.0 2.0 0.0 15.11 MB

This library offers a simple way to translucent system UI styling and tint color for status bar.It can work above API 19(KitKat 4.4).

Java 100.00%

translucentbar's Introduction

Background

Android 4.4 (KitKat) introduced translucent system UI styling for status bar, then Android 5.0+ offers simple ways to enable translucency in Activity( android:windowTranslucentStatus) and tint color for status bar,But how to perfectly achieve translucent system UI styling for status bar is troublesome as before,particularly compatible with KitKat. Here are some trouble you must care about:

  • FitsSystemWindows is puzzling,how to accurately use fitsSystemWindows is full of challenges(hint: it would get different effects between KitKat and Lollipop. CoordinatorLayout、AppBarLayout、CollapsingToolbarLayout has reimplemented FitsSystemWindows)
  • How to make view(ImageView) over status bar easily When use CollapsingToolbarLayout
  • How to tint color for status bar and action bar expediently(especial on KitKat)
  • How to make translucent status bar apply on Fragment and freely change color or style when fragment transform.
  • How to make status bar translucent or transparent expediently (only Lollipop)
  • ....

TranslucentBar

TranslucentBar is come to resolve all problem we mention above. This library offers a simple way to translucent system UI styling and tint color for status bar,you don't need to care for any about "FitsSystemWindows" and status bar colors. it can work above API 19(KitKat 4.4).

Demo

Apk Download:TranslucentBar.apk

Download

  compile 'com.kelin.translucentbar:library:0.7.0' 

Usage

1、Values-Styles

You must first enable translucency and remove ActionBar and WindowTitle in your Activity. Just add following styles,then set it for your Activity in AndroidManifest.xml.After that,you must make sure add toolbar in your layout to obtain action bar in your view.

values

<style name="AppTheme.TranslucentStatusBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

values-v19

<style name="AppTheme.TranslucentStatusBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>

2、Activity

translucent

make status bar translucent and tint color,if you don't set any colors,toolbar would be tinted with @color/colorPrimary and status bar would be tinted with @color/colorPrimaryDark

transparent

when set windowTranslucentStatus true, system will add translucent gray shade above of status bar,this is standard style of material design,but some times,you may want to remove the shade, for example: if the color of ActionBar is white and now show a gray shape above of white status bar is so ugly exactly!

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ....
        TranslucentBarManager translucentBarManager = new TranslucentBarManager(this);
        translucentBarManager.translucent(this);
        //or translucentBarManager.transparent(this);
        .....
    }
translucent(SampleActivity.this) transparent(SampleActivity.this)

Tint Color

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ......
        TranslucentBarManager translucentBarManager = new TranslucentBarManager(this);   
        translucentBarManager.translucent(this,android.R.color.holo_purple);
        //or translucentBarManager.transparent(this,android.R.color.holo_purple);
        .....
    }
translucent(activity,color) transparent(activity,color)

3、Fragment

Nothing less than Activity ,but translucent(transparent) method must call in onCreateView to take effect.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_image_over_statusbar, container, false);
    TranslucentBarManager translucentBarManager = new TranslucentBarManager(this);
    translucentBarManager.translucent(this, view, android.R.color.holo_orange_dark);
    return view;
 }
translucent(fragment,rootView,color) transparent(fragment,rootView,color)

License

Copyright 2016 Kelin Hong
 
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
 
http://www.apache.org/licenses/LICENSE-2.0
 
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 

translucentbar's People

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.