Code Monkey home page Code Monkey logo

translucent's Introduction

app沉浸式的封装(兼容4.4,以下效果都是4.4版本)

如何使用

添加依赖

step1、项目gradle中

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

step2、app gradle中

	dependencies {
	        compile 'com.github.livesun:translucent:v1.0'
	}

设置AppTheme为NoActionBar 例如:

    <style>
	<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorAccent</item>
        <item name="colorAccent">@color/colorAccent</item>
     
    </style>

注意:如果xml布局中写了这个属性,需要删除掉

fitsSysytemWindows=“true"

1、继承BaseTranslucentActivity。

 MainActivity extends BaseTranslucentActivity

2、纯颜色调用setStatusColor(),在setContentView之后。

setContentView(R.layout.activity_main);
LinearLayout title= (LinearLayout) findViewById(R.id.title);
//需要沉浸的标题栏,可以是Toolbar,LinearLayout,等等
//参数二,为颜色id
//参数三,石否开启手动隐藏展示状态栏和导航栏
setStatusColor(title,R.color.colorPrimary,false);

开启手动隐藏和展示的效果,可以通过改方式实现全屏效果

steep_toggel2

3、图片沉浸效果,调用setStatusPicture();

setContentView(R.layout.activity_main);
LinearLayout title= (LinearLayout) findViewById(R.id.title);
//需要沉浸的标题栏,可以是Toolbar,LinearLayout,等等
//参数二,为图片id
//参数三,石否开启手动隐藏展示状态栏和导航栏
setStatusPicture(title,R.drawable.demobg,false);

效果如下

steep03

4、标题栏和状态栏颜色一致,调用 setStatusAndNaviagtion(),并且需要重载setNavigationBarisTranslucent方法为true

/**
     * 是否设置导航条为透明,默认返回false。
     * @return
     */
    @Override
    protected boolean setNavigationBarisTranslucent() {
        return true;
    }

setContentView(R.layout.activity_main);
LinearLayout title= (LinearLayout) findViewById(R.id.title);
//参数一,需要沉浸的标题栏,可以是Toolbar,LinearLayout,等等
//参数二,展示的navigation的view,4.4版本需要手动在xml布局写死。
//参数三,为颜色id
 setStatusAndNaviagtion(title,nivagtion,R.color.colorPrimary);
 
 
 
 4.4 xml布局需要这样
 
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

   <LinearLayout
       android:id="@+id/title"
       android:orientation="vertical"
       android:layout_width="match_parent"
       android:layout_height="250dp"
       android:gravity="center"
       >
      <TextView
          android:text="ddddddddd"
          android:textSize="15sp"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" />
   </LinearLayout>


   <View
       android:layout_alignParentBottom="true"
       android:id="@+id/nivagtion"
       android:layout_width="match_parent"
       android:layout_height="0.1dp"/>
</RelativeLayout>
 

效果如下

steep04

5、关于setNavigationBarisTranslucent方法,默认是不会把4.4版本到5.0版本设置为透明色。

如有需要可以重载该方法

 /**
     * 是否设置导航条为透明,默认返回false。
     * @return
     */
    @Override
    protected boolean setNavigationBarisTranslucent() {
        return true;
    }

效果如下 false的效果: ota za 5fvww1io2lb_k7hn

true的效果 s k7hh8jv ux9_ 6 ugguw

博客讲解地址:https://livesun.github.io/2017/06/16/translucent/

translucent's People

Contributors

livesun avatar

Stargazers

 avatar  avatar

Watchers

James Cloos 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.