Skip to content

Commit

Permalink
update 3.0.0-beta04
Browse files Browse the repository at this point in the history
  • Loading branch information
geyifeng committed May 27, 2019
1 parent ccfdd4d commit 93e5463
Show file tree
Hide file tree
Showing 40 changed files with 623 additions and 157 deletions.
52 changes: 11 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![logo](https://github.com/gyf-dev/Screenshots/blob/master/ImmersionBar/readme_head.png)
# ImmersionBar -- android 4.4以上沉浸式实现
[![version](https://img.shields.io/badge/version-3.0.0--beta03-brightgreen.svg)](https://bintray.com/geyifeng/maven/immersionbar)[![author](https://img.shields.io/badge/author-gyf--dev-orange.svg)](https://github.com/gyf-dev)[![简书](https://img.shields.io/badge/%E7%AE%80%E4%B9%A6-HeLe%E5%B0%8F%E5%AD%90%E6%8B%BD-blue.svg)](https://www.jianshu.com/p/2a884e211a62)[![QQ群](https://img.shields.io/badge/QQ%E7%BE%A4-314360549-red.svg)]()
[![version](https://img.shields.io/badge/version-3.0.0--beta04-brightgreen.svg)](https://bintray.com/geyifeng/maven/immersionbar) [![author](https://img.shields.io/badge/author-gyf--dev-orange.svg)](https://github.com/gyf-dev) [![简书](https://img.shields.io/badge/%E7%AE%80%E4%B9%A6-HeLe%E5%B0%8F%E5%AD%90%E6%8B%BD-blue.svg)](https://www.jianshu.com/p/2a884e211a62) [![QQ群](https://img.shields.io/badge/QQ%E7%BE%A4-314360549-red.svg)]()

## 直接看效果图,最下面有各个版本的效果图
<img width="300" src="https://github.com/gyf-dev/Screenshots/blob/master/ImmersionBar/Screenshot_6.0.gif"/>
Expand All @@ -9,20 +9,20 @@
> android studio
```groovy
// 基础依赖包,必须要依赖
implementation 'com.gyf.immersionbar:immersionbar:3.0.0-beta03'
implementation 'com.gyf.immersionbar:immersionbar:3.0.0-beta04'
// fragment快速实现(可选)
implementation 'com.gyf.immersionbar:immersionbar-components:3.0.0-beta03'
implementation 'com.gyf.immersionbar:immersionbar-components:3.0.0-beta04'
// kotlin扩展(可选)
implementation 'com.gyf.immersionbar:immersionbar-ktx:3.0.0-beta03'
implementation 'com.gyf.immersionbar:immersionbar-ktx:3.0.0-beta04'
```
## 2.x版本使用说明
### [点我查看2.x版本使用说明](https://github.com/gyf-dev/ImmersionBar/blob/master/README_2.x.md)
#### [点我查看2.x版本使用说明](https://github.com/gyf-dev/ImmersionBar/blob/master/README_2.x.md)

## 版本说明
### [点我查看版本说明](https://github.com/gyf-dev/ImmersionBar/wiki)
#### [点我查看版本说明](https://github.com/gyf-dev/ImmersionBar/wiki)

## 下载demo
### [点我下载immersionBar-3.0.0beta03.apk](https://github.com/gyf-dev/ImmersionBar/blob/master/apk/immersionBar-3.0.0beta03.apk)
#### [点我下载immersionBar-3.0.0beta04.apk](https://github.com/gyf-dev/ImmersionBar/blob/master/apk/immersionBar-3.0.0beta04.apk)

## 关于使用AndroidX支持库
- 如果你的项目中使用了AndroidX支持库,请在你的gradle.properties加入如下配置,如果已经配置了,请忽略
Expand All @@ -32,7 +32,7 @@
```
## 关于全面屏与刘海
### 关于全面屏
#### 关于全面屏
在manifest加入如下配置,四选其一,或者都写
① 在manifest的Application节点下加入
Expand All @@ -51,7 +51,7 @@
```
④ 升级targetSdkVersion为25以上版本

### 关于刘海屏
#### 关于刘海屏
在manifest的Application节点下加入,vivo和oppo没有找到相关配置信息
```xml
<!--适配华为(huawei)刘海屏-->
Expand All @@ -64,8 +64,7 @@
android:value="portrait|landscape" />
```

## 用法
### 初始化
## Api详解
- 基础用法

```java
Expand Down Expand Up @@ -372,36 +371,7 @@
```

## 问题汇总
#### 1)、为什么顶部图片没法沉浸?
答:但凡当前界面使用了fitsSystemWindow相关的属性或者方法为true都没法让顶部图片沉浸,所以你就要检查你的代码了,比如:
- ①检查你是否使用了ImmersionBar的fitsSystemWindow(true)方法;
- ②检查你的代码中是否调用了view的setFitsSystemWindow(true)方法;
- ③检查你的布局xml里是否使用了android:fitsSystemWindows="true"属性;
- ④检查你的style文件里是否使用了<item name="android:fitsSystemWindows">true</item>属性。

#### 2)、immersionbar-components和immersionbar-ktx具体是干嘛的?
答:①immersionbar-components:作用是加快你在Fragment里实现沉浸式。如果你的Fragment是以show/hide或者结合viewpager一起使用的,并且界面之间沉浸式不相同,而且又想在Fragment里使用沉浸式代码的话,因为受到Fragment生命周期的影响,必须要在Fragment里做一些相应的出来,这样才可以正常使用沉浸式。比如对于show/hide方式来说,你必须要在onHiddenChanged方法里做一些沉浸式处理;对于结合viewpager来说,就必须要在setUserVisibleHint方法里做一些处理,而immersionbar-components里的Fragment相关的类就已经做好了这方面的处理,所以就可以在initImmersionBar方法里快速实现不同样式的沉浸式了。
②immersionbar-ktx:kotlin语言的一些扩展方法,让你在kotlin使用起来更方便,比如java里的
```java
ImmersionBar.with(this).init();
```
在kotlin的写法就是
```kotlin
immersionBar()
```
再比如java里的
```java
ImmersionBar.with(this).statusBarColor(R.color.colorPrimary).init();
```
在kotlin的写法就是
```kotlin
immersionBar {
statusBarColor(R.color.colorPrimary)
}
```
除此之外还有一些其他静态方法的简写,具体可以参考这个类[KotlinActivity](https://github.com/gyf-dev/ImmersionBar/blob/master/immersionbar-simple/src/main/java/com/gyf/immersionbar/simple/activity/KotlinActivity.kt)的演示


#### 点我[问题汇总](https://github.com/gyf-dev/ImmersionBar/wiki/questions)


## 效果图 ##
Expand Down
Binary file removed apk/immersionBar-3.0.0beta03.apk
Binary file not shown.
Binary file added apk/immersionBar-3.0.0beta04.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

buildscript {
ext.kotlin_version = '1.3.31'
ext.immersionbar_version = '3.0.0-beta03'
ext.immersionbar_version = '3.0.0-beta04'
repositories {
google()
jcenter()
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Tue May 14 14:36:23 CST 2019
#Mon May 27 16:27:12 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
1 change: 0 additions & 1 deletion immersionbar-components/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ apply plugin: 'com.novoda.bintray-release'

android {
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
minSdkVersion 14
Expand Down
4 changes: 2 additions & 2 deletions immersionbar-simple/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ dependencies {
//下拉刷新上拉加载
implementation 'com.lcodecorex:tkrefreshlayout:1.0.7'
//圆形imageView
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'de.hdodenhof:circleimageview:3.0.0'
// 内存泄漏检测
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.3'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'
testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'
// Fragment框架
implementation 'me.yokeyword:fragmentation:1.3.6'
//腾讯bugly
implementation 'com.tencent.bugly:crashreport:2.6.6.1'
implementation 'com.tencent.bugly:crashreport:2.8.6'
// Rx
implementation "io.reactivex.rxjava2:rxjava:2.2.8"
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
Expand Down
11 changes: 7 additions & 4 deletions immersionbar-simple/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@
<!-- 适配全面屏 -->
<meta-data
android:name="android.max_aspect"
android:value="2.4" />
<!-- 适配华为(hua wei)刘海屏 -->
android:value="2.4" /> <!-- 适配华为(hua wei)刘海屏 -->
<meta-data
android:name="android.notch_support"
android:value="true" />
<!-- 适配小米(xiao mi)刘海屏 -->
android:value="true" /> <!-- 适配小米(xiao mi)刘海屏 -->
<meta-data
android:name="notch.config"
android:value="portrait|landscape" />
Expand Down Expand Up @@ -149,6 +147,10 @@
android:name=".activity.DialogActivity"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboardHidden"
android:windowSoftInputMode="adjustResize" />
<activity
android:name=".activity.PopupActivity"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboardHidden"
android:windowSoftInputMode="adjustResize" />
<activity
android:name=".activity.BlogActivity"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboardHidden" />
Expand All @@ -171,6 +173,7 @@
<service
android:name=".service.NetworkService"
android:permission="android.permission.BIND_JOB_SERVICE" />

<receiver android:name=".receiver.NetworkBroadCastReceiver" />
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_full:
mDialogWindow.setGravity(Gravity.TOP);
mDialogWindow.setWindowAnimations(R.style.RightDialog);
mDialogWindow.setWindowAnimations(R.style.RightAnimation);
mDialogWindow.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
ImmersionBar.with(this, mAlertDialog)
.titleBar(toolbar)
Expand All @@ -124,7 +124,7 @@ public void onClick(View view) {
break;
case R.id.btn_top:
mDialogWindow.setGravity(Gravity.TOP);
mDialogWindow.setWindowAnimations(R.style.TopDialog);
mDialogWindow.setWindowAnimations(R.style.TopAnimation);
mDialogWindow.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, widthAndHeight[1] / 2);
ImmersionBar.with(this, mAlertDialog)
.titleBar(toolbar)
Expand All @@ -134,15 +134,15 @@ public void onClick(View view) {
break;
case R.id.btn_bottom:
mDialogWindow.setGravity(Gravity.BOTTOM);
mDialogWindow.setWindowAnimations(R.style.BottomDialog);
mDialogWindow.setWindowAnimations(R.style.BottomAnimation);
mDialogWindow.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, widthAndHeight[1] / 2);
ImmersionBar.with(this, mAlertDialog)
.navigationBarColor(R.color.cool_green_normal)
.init();
break;
case R.id.btn_left:
mDialogWindow.setGravity(Gravity.TOP | Gravity.START);
mDialogWindow.setWindowAnimations(R.style.LeftDialog);
mDialogWindow.setWindowAnimations(R.style.LeftAnimation);
mDialogWindow.setLayout(widthAndHeight[0] / 2, ViewGroup.LayoutParams.MATCH_PARENT);
ImmersionBar.with(this, mAlertDialog)
.titleBar(toolbar)
Expand All @@ -153,7 +153,7 @@ public void onClick(View view) {
break;
case R.id.btn_right:
mDialogWindow.setGravity(Gravity.TOP | Gravity.END);
mDialogWindow.setWindowAnimations(R.style.RightDialog);
mDialogWindow.setWindowAnimations(R.style.RightAnimation);
mDialogWindow.setLayout(widthAndHeight[0] / 2, ViewGroup.LayoutParams.MATCH_PARENT);
ImmersionBar.with(this, mAlertDialog)
.titleBar(toolbar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class KotlinActivity : BaseKotlinActivity(R.layout.activity_params) {
mTvStatus.text = "${mTvStatus.title}$statusBarHeight".content()
mTvHasNav.text = "${mTvHasNav.title}$hasNavigationBar".content()
mTvNav.text = "${mTvNav.title}$navigationBarHeight".content()
mTvNavWidth.text = "${mTvNavWidth.title}$navigationBarWidth".content()
mTvAction.text = "${mTvAction.title}$actionBarHeight".content()
mTvHasNotch.post { mTvHasNotch.text = "${mTvHasNotch.title}$hasNotchScreen".content() }
mTvNotchHeight.post { mTvNotchHeight.text = "${mTvNotchHeight.title}$notchHeight".content() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.widget.LinearLayoutManager;
Expand Down Expand Up @@ -116,6 +117,7 @@ protected void initData() {
@SuppressLint("SetTextI18n")
@Override
protected void initView() {
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
showSplash();
GlideUtils.loadBlurry(ivBg, Utils.getPic());
mMainAdapter = new MainAdapter();
Expand Down Expand Up @@ -196,61 +198,64 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
intent = new Intent(this, DialogActivity.class);
break;
case 9:
drawer.openDrawer(Gravity.START);
intent = new Intent(this, PopupActivity.class);
break;
case 10:
intent = new Intent(this, CoordinatorActivity.class);
drawer.openDrawer(Gravity.START);
break;
case 11:
intent = new Intent(this, TabLayoutActivity.class);
intent = new Intent(this, CoordinatorActivity.class);
break;
case 12:
intent = new Intent(this, TabLayout2Activity.class);
intent = new Intent(this, TabLayoutActivity.class);
break;
case 13:
intent = new Intent(this, WebActivity.class);
intent = new Intent(this, TabLayout2Activity.class);
break;
case 14:
intent = new Intent(this, ActionBarActivity.class);
intent = new Intent(this, WebActivity.class);
break;
case 15:
intent = new Intent(this, FlymeActivity.class);
intent = new Intent(this, ActionBarActivity.class);
break;
case 16:
intent = new Intent(this, OverActivity.class);
intent = new Intent(this, FlymeActivity.class);
break;
case 17:
intent = new Intent(this, KeyBoardActivity.class);
intent = new Intent(this, OverActivity.class);
break;
case 18:
intent = new Intent(this, AllEditActivity.class);
intent = new Intent(this, KeyBoardActivity.class);
break;
case 19:
intent = new Intent(this, LoginActivity.class);
intent = new Intent(this, AllEditActivity.class);
break;
case 20:
intent = new Intent(this, WhiteBarActivity.class);
intent = new Intent(this, LoginActivity.class);
break;
case 21:
intent = new Intent(this, AutoDarkModeActivity.class);
intent = new Intent(this, WhiteBarActivity.class);
break;
case 22:
ImmersionBar.with(this).hideBar(BarHide.FLAG_HIDE_STATUS_BAR).init();
intent = new Intent(this, AutoDarkModeActivity.class);
break;
case 23:
ImmersionBar.with(this).hideBar(BarHide.FLAG_HIDE_STATUS_BAR).init();
break;
case 24:
if (ImmersionBar.hasNavigationBar(this)) {
ImmersionBar.with(this).hideBar(BarHide.FLAG_HIDE_NAVIGATION_BAR).init();
} else {
Toast.makeText(this, "当前设备没有导航栏或者导航栏已经被隐藏或者低于4.4系统", Toast.LENGTH_SHORT).show();
}
break;
case 24:
case 25:
ImmersionBar.with(this).hideBar(BarHide.FLAG_HIDE_BAR).init();
break;
case 25:
case 26:
ImmersionBar.with(this).hideBar(BarHide.FLAG_SHOW_BAR).init();
break;
case 26:
case 27:
if (ImmersionBar.hasNavigationBar(this)) {
BarParams barParams = ImmersionBar.with(this).getBarParams();
if (barParams.fullScreen) {
Expand All @@ -262,14 +267,14 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
Toast.makeText(this, "当前设备没有导航栏或者导航栏已经被隐藏或者低于4.4系统", Toast.LENGTH_SHORT).show();
}
break;
case 27:
case 28:
if (ImmersionBar.isSupportStatusBarDarkFont()) {
ImmersionBar.with(this).statusBarDarkFont(true).init();
} else {
Toast.makeText(this, "当前设备不支持状态栏字体变色", Toast.LENGTH_SHORT).show();
}
break;
case 28:
case 29:
ImmersionBar.with(this).statusBarDarkFont(false).init();
break;
default:
Expand Down Expand Up @@ -311,18 +316,27 @@ public void onClick(View view) {
* 展示Splash
*/
private void showSplash() {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
mSplashFragment = (SplashFragment) getSupportFragmentManager().findFragmentByTag(SplashFragment.class.getSimpleName());
if (mSplashFragment == null) {
if (mSplashFragment != null) {
if (mSplashFragment.isAdded()) {
transaction.show(mSplashFragment).commitAllowingStateLoss();
} else {
transaction.remove(mSplashFragment).commitAllowingStateLoss();
mSplashFragment = SplashFragment.newInstance();
transaction.add(R.id.fl_content, mSplashFragment, SplashFragment.class.getSimpleName()).commitAllowingStateLoss();
}
} else {
mSplashFragment = SplashFragment.newInstance();
mSplashFragment.setOnSplashListener((time, totalTime) -> {
if (time != 0) {
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
} else {
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
}
});
transaction.add(R.id.fl_content, mSplashFragment, SplashFragment.class.getSimpleName()).commitAllowingStateLoss();
}
getSupportFragmentManager().beginTransaction().add(R.id.fl_content, mSplashFragment, SplashFragment.class.getSimpleName()).commitAllowingStateLoss();
mSplashFragment.setOnSplashListener((time, totalTime) -> {
if (time != 0) {
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
} else {
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
}
});
}

private void addHeaderView() {
Expand Down
Loading

0 comments on commit 93e5463

Please sign in to comment.