Skip to content

Commit

Permalink
发布2.1.0版本,修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
gyf-dev committed May 12, 2017
0 parents commit de00eee
Show file tree
Hide file tree
Showing 75 changed files with 3,208 additions and 0 deletions.
113 changes: 113 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

# Created by https://www.gitignore.io/api/androidstudio

### AndroidStudio ###
# Covers files to be ignored for android development using Android Studio.

# Built application files
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
.gradle
.gradle/
build/

# Signing files
.signing/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio
/*/build/
/*/local.properties
/*/out
/*/*/build
/*/*/production
captures/
.navigation/
*.ipr
*~
*.swp

# Android Patch
gen-external-apklibs

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# NDK
obj/

# IntelliJ IDEA
*.iml
*.iws
/out/

# User-specific configurations
.idea

# Keystore files
*.jks

# OS-specific files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# Legacy Eclipse project files
.classpath
.project

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
#*.jar
*.war
*.ear

# virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml)
hs_err_pid*

## Plugin-specific files:

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Mongo Explorer plugin
.idea/mongoSettings.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# End of https://www.gitignore.io/api/androidstudio
.idea/copyright/
gradle/wrapper/gradle-wrapper.jar
170 changes: 170 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# ImmersionBar -- android 4.4以上沉浸式实现

## 使用
android studio用户用法如下,2.x.x版本全新的Api,调用更方便

compile 'com.gyf.barlibrary:barlibrary:2.1.0'
eclipse用户直接下载jar包

[barlibrary-2.1.0.jar](https://github.com/gyf-dev/ImmersionBar/blob/master/jar/barlibrary-2.1.0.jar)

版本说明

>2.1.0
- 全新的链式调用,更方便,删除了1.x.x版本Api
- 修复了4.4不能时刻改变颜色的bug
- 修复了4.4 activity全屏时底部被导航栏遮挡的bug
- 修复状态栏和布局重叠的问题,调用fitsSystemWindows(true)即可,必须指定状态栏的颜色statusBarColor()
- 增加了View支持变色功能
- 删除[SystemBarTint](https://github.com/jgilfelt/SystemBarTint)的库的依赖

### [1.x.x 用户请点击](https://github.com/gyf-dev/ImmersionBar/blob/master/README_1.x.md)

## 下载demo
###[点我](https://github.com/gyf-dev/ImmersionBar/blob/master/apk/sample-debug.apk)

## 用法
### 初始化
- 基础用法(已经可以满足日常沉浸式)

```
ImmersionBar.with(this).init();
```
- 高级用法(每个参数的意义)
```
ImmersionBar.with(this)
.transparentStatusBar() //透明状态栏,不写默认透明色
.transparentNavigationBar() //透明导航栏,不写默认黑色(设置此方法,fullScreen()方法自动为true)
.transparentBar() //透明状态栏和导航栏,不写默认状态栏为透明色,导航栏为黑色(设置此方法,fullScreen()方法自动为true)
.statusBarColor(R.color.colorPrimary) //状态栏颜色,不写默认透明色
.navigationBarColor(R.color.colorPrimary) //导航栏颜色,不写默认黑色
.barColor(R.color.colorPrimary) //同时自定义状态栏和导航栏颜色,不写默认状态栏为透明色,导航栏为黑色
.statusBarAlpha(0.3f) //状态栏透明度,不写默认0.0f
.navigationBarAlpha(0.4f) //导航栏透明度,不写默认0.0F
.barAlpha(0.3f) //状态栏和导航栏透明度,不写默认0.0f
.statusBarDarkFont(true) //状态栏字体是深色,不写默认为亮色
.fullScreen(true) //有导航栏的情况下,activity全屏显示,也就是activity最下面被导航栏覆盖,不写默认非全屏
.hideBar(BarHide.FLAG_HIDE_BAR) //隐藏状态栏或导航栏或两者,不写默认不隐藏
.setViewSupportTransformColor(toolbar) //设置支持view变色,支持一个view,不指定颜色,默认和状态栏同色,还有两个重载方法
.addViewSupportTransformColor(toolbar) //设置支持view变色,可以添加多个view,不指定颜色,默认和状态栏同色,还有两个重载方法
.fitsSystemWindows(false) //解决状态栏和布局重叠问题,默认为false,当为true时一定要指定statusBarColor(),不然状态栏为透明色
.statusBarColorTransform(R.color.orange) //状态栏变色后的颜色
.navigationBarColorTransform(R.color.orange) //导航栏变色后的颜色
.barColorTransform(R.color.orange) //状态栏和导航栏变色后的颜色
.removeSupportView() //移除通过setViewSupportTransformColor()方法指定的view
.removeSupportView(toolbar) //移除指定view支持
.removeSupportAllView() //移除全部view支持
.init(); //必须调用方可沉浸式
```
### 关闭销毁
- 在activity的onDestroy方法中执行
```
ImmersionBar.with(this).destroy();
```
## 建议
- 建议在BaseActivity中初始化和销毁
```
Ipublic class BaseActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ImmersionBar.with(this).init();
}
@Override
protected void onDestroy() {
super.onDestroy();
ImmersionBar.with(this).destroy(); //不调用该方法,如果界面bar发生改变,在不关闭app的情况下,退出此界面再进入将记忆最后一次bar改变的状态
}
}
```
## 状态栏与布局顶部重叠解决方案,三种方案任选其一
- ① 使用dimen自定义状态栏高度
```
values-v19/dimens.xml
<dimen name="status_bar_height">25dp</dimen>
values/dimens.xml
<dimen name="status_bar_height">0dp</dimen>
```
然后在布局界面添加view标签,高度指定为status_bar_height
```
<View
android:layout_width="match_parent"
android:layout_height="@dimen/status_bar_height" />
```
- ② 使用ImmersionBar的fitsSystemWindows()方法
```
ImmersionBar.with(this)
.statusBarColor(R.color.colorPrimary)
.fitsSystemWindows(true) //使用该属性必须指定状态栏的颜色,不然状态栏透明,很难看
.init();
```
- ③ 使用系统的fitsSystemWindows属性
```
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true">
</LinearLayout>
```
然后使用ImmersionBar时候必须指定状态栏颜色
```
ImmersionBar.with(this)
.statusBarColor(R.color.colorPrimary)
.init();
```
- 注意:②和③的fitsSystemWindows方法和属性,不要一起使用
## 状态栏和导航栏其它方法
- public static boolean hasNavigationBar(Activity activity)
判断是否存在导航栏
- public static int getNavigationBarHeight(Activity activity)
获得导航栏的高度
- public static int getNavigationBarWidth(Activity activity)
获得导航栏的宽度
- public static boolean isNavigationAtBottom(Activity activity)
判断导航栏是否在底部
- public static int getStatusBarHeight(Activity activity)
或得状态栏的高度
- public static int getActionBarHeight(Activity activity)
或得ActionBar得高度
## 效果图 ##
#### 说明 ####
- 这是状态栏
![image](https://github.com/gyf-dev/ImmersionBar/blob/master/screenshots/StatusBar.png)
- 这是导航栏(有些手机没有导航栏)
![image](https://github.com/gyf-dev/ImmersionBar/blob/master/screenshots/NavigationBar.png)
#### 动态图 ####
- android 6.0 有导航栏效果
<img width="300" src="https://github.com/gyf-dev/ImmersionBar/blob/master/screenshots/Screenshot_6.0.gif"/>
- android 4.4 有导航栏效果
<img width="300" src="https://github.com/gyf-dev/ImmersionBar/blob/master/screenshots/Screenshot_4.4.gif"/>
- android 4.4 没有导航栏效果
<img width="300" src="https://github.com/gyf-dev/ImmersionBar/blob/master/screenshots/Screenshot_4.4_no.gif"/>
## 联系我 ##
- QQ 969565471
- WeChat(微信)
<img width="300" src="https://github.com/gyf-dev/ImmersionBar/blob/master/screenshots/wechat.JPG"/>
110 changes: 110 additions & 0 deletions README_1.x.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# ImmersionBar -- android 4.4以上沉浸式实现 #

## 使用 ##
该项目已经上传到jCenter仓库中,使用的时候可以直接使用compile依赖,android studio用户用法如下

compile 'com.gyf.barlibrary:barlibrary:1.2.2'
eclipse用户直接下载jar包

[barlibrary-1.2.2.jar](https://github.com/gyf-dev/ImmersionBar/blob/master/jar/barlibrary-1.2.2.jar)

历史版本

[barlibrary-1.2.1.jar](https://github.com/gyf-dev/ImmersionBar/blob/master/jar/barlibrary-1.2.1.jar)

版本说明

>1.2.2
- 修复当设置BarManager.setBarColor(this, BarType.STATUS_BAR, ContextCompat.getColor(this, R.color.colorPrimary), false)时,导航栏为白色的问题
- 增加setBarColor(Activity activity, int BarColor, boolean isFullScreen)方法
- 其他小修小补

## 下载demo ##
[点我](https://github.com/gyf-dev/ImmersionBar/blob/master/apk/sample-debug.apk)

## 用法 BarManager.xxx()方法 ##
#### ① 以下方法是自定义状态栏和导航栏颜色,任选其一使用,style风格使用NoActionBar效果更佳 ####

![image](https://github.com/gyf-dev/ImmersionBar/blob/master/screenshots/Screenshot3.png)

- public static void setBarColor(Activity activity)

Activity非全屏,默认状态栏为透明色,导航栏为黑色

- public static void setBarColor(Activity activity,boolean isFullScreen)

isFullScreen为true状态栏和导航栏全为透明色,isFullScreen为false同public static void immersionBar(Activity activity)

- public static void setBarColor(Activity activity, int BarColor, boolean isFullScreen)

设置状态栏和导航栏颜色相同

- public static void setBarColor(Activity activity, BarType barType,int BarColor,boolean isFullScreen)

自定义状态栏和导航栏其中一个的颜色或者全部为同一种颜色

- public static void setBarColor(Activity activity, int StatusBarColor, int NavigationBarColor,boolean isFullScreen)

自定义状态栏和导航栏颜色


> isFullScreen说明:
>
true--Activity全屏显示,但导航栏不会被隐藏,导航栏依然可见,Activity底部布局部分会被导航栏遮住。
>
false--Activity非全屏显示,但导航栏不会被隐藏,导航栏依然可见,Activity底部布局不会被导航栏遮住。

#### ② 状态栏和导航栏其它方法 ####
- public static void hideBar(Activity activity, BarHide barHide)

隐藏或显示状态栏和导航栏。 状态栏和导航栏的颜色不起作用,都是透明色,以最后一次调用为准

- public static boolean hasNavigationBar(Activity activity)

判断是否存在导航栏

- public static int getNavigationBarHeight(Activity activity)

获得导航栏的高度

- public static int getNavigationBarWidth(Activity activity)

获得导航栏的宽度

- public static boolean isNavigationAtBottom(Activity activity)

判断导航栏是否在底部

- public static int getStatusBarHeight(Activity activity)

或得状态栏的高度

- public static int getActionBarHeight(Activity activity)

或得ActionBar得高度

- public static void setStatusBarDarkFont(Activity activity, boolean dark)

设置状态栏字体颜色,dark为true为深色,否则为亮色(android6.0以上或者miuiv6以上或者flymeOS)

## 效果图 ##
#### 说明 ####
- 这是状态栏
![image](https://github.com/gyf-dev/ImmersionBar/blob/master/screenshots/StatusBar.png)
- 这是导航栏(有些手机没有导航栏)
![image](https://github.com/gyf-dev/ImmersionBar/blob/master/screenshots/NavigationBar.png)
#### 动态图 ####
![image](https://github.com/gyf-dev/ImmersionBar/blob/master/screenshots/Screenshot_gif.gif)
#### 静态图 ####
![image](https://github.com/gyf-dev/ImmersionBar/blob/master/screenshots/Screenshot0.png)
![image](https://github.com/gyf-dev/ImmersionBar/blob/master/screenshots/Screenshot1.png)
![image](https://github.com/gyf-dev/ImmersionBar/blob/master/screenshots/Screenshot2.png)
## 参考 ##
- Android 4.4使用的是github上第三方库实现,参考地址:https://github.com/jgilfelt/SystemBarTint
- Android 5.0以上使用自带Api实现

## 联系我 ##
- QQ 969565471
- WeChat(微信)

![image](https://github.com/gyf-dev/ImmersionBar/blob/master/screenshots/wechat.JPG)
Binary file added apk/sample-debug.apk
Binary file not shown.
1 change: 1 addition & 0 deletions barlibrary/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Loading

0 comments on commit de00eee

Please sign in to comment.