├── .gitignore ├── .idea ├── caches │ └── build_file_checksums.ser ├── codeStyles │ └── Project.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── render.experimental.xml ├── runConfigurations.xml └── vcs.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── cy │ │ └── statusnavigationtrans │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── cy │ │ │ └── statusnavigationtrans │ │ │ ├── FullScreenActivity.java │ │ │ ├── HideNavigationBarActivity.java │ │ │ ├── HideStatusBarActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── Navigation0Activity.java │ │ │ ├── Navigation1Activity.java │ │ │ ├── Navigation2Activity.java │ │ │ ├── Status00Activity.java │ │ │ ├── Status0Activity.java │ │ │ ├── Status2Activity.java │ │ │ ├── Status5Activity.java │ │ │ ├── Status6Activity.java │ │ │ └── StatusNavigationSwitchActivity.java │ └── res │ │ ├── drawable-xhdpi │ │ ├── back.png │ │ └── huge.jpg │ │ ├── layout │ │ ├── activity_full_screen.xml │ │ ├── activity_hide_navigation_bar.xml │ │ ├── activity_hide_status_bar.xml │ │ ├── activity_main.xml │ │ ├── activity_nav1.xml │ │ ├── activity_nav2.xml │ │ ├── activity_navigation0.xml │ │ ├── activity_status0.xml │ │ ├── activity_status00.xml │ │ ├── activity_status2.xml │ │ ├── activity_status5.xml │ │ ├── activity_status6.xml │ │ └── activity_status_navigation_switch.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── cy │ └── statusnavigationtrans │ └── ExampleUnitTest.java ├── build.gradle ├── gif ├── 1.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── 6.png ├── 7.png ├── 8.png └── 9.png ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── translucentparent ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src ├── androidTest └── java │ └── com │ └── cy │ └── translucentparent │ └── ExampleInstrumentedTest.java ├── main ├── AndroidManifest.xml └── java │ └── com │ └── cy │ └── translucentparent │ ├── LogUtils.java │ ├── NavigationBarView.java │ ├── ScreenUtils.java │ ├── StatusBarView.java │ ├── StatusNavigationActivity.java │ └── StatusNavigationUtils.java └── test └── java └── com └── cy └── translucentparent └── ExampleUnitTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnJiaoDe/StatusNavigationTransparent/69943ef8fc79b88eafce38ce0ceb8e843b5e0baa/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | xmlns:android 14 | 15 | ^$ 16 | 17 | 18 | 19 |
20 |
21 | 22 | 23 | 24 | xmlns:.* 25 | 26 | ^$ 27 | 28 | 29 | BY_NAME 30 | 31 |
32 |
33 | 34 | 35 | 36 | .*:id 37 | 38 | http://schemas.android.com/apk/res/android 39 | 40 | 41 | 42 |
43 |
44 | 45 | 46 | 47 | .*:name 48 | 49 | http://schemas.android.com/apk/res/android 50 | 51 | 52 | 53 |
54 |
55 | 56 | 57 | 58 | name 59 | 60 | ^$ 61 | 62 | 63 | 64 |
65 |
66 | 67 | 68 | 69 | style 70 | 71 | ^$ 72 | 73 | 74 | 75 |
76 |
77 | 78 | 79 | 80 | .* 81 | 82 | ^$ 83 | 84 | 85 | BY_NAME 86 | 87 |
88 |
89 | 90 | 91 | 92 | .* 93 | 94 | http://schemas.android.com/apk/res/android 95 | 96 | 97 | ANDROID_ATTRIBUTE_ORDER 98 | 99 |
100 |
101 | 102 | 103 | 104 | .* 105 | 106 | .* 107 | 108 | 109 | BY_NAME 110 | 111 |
112 |
113 |
114 |
115 |
116 |
-------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/render.experimental.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 文章目录 3 | 4 | GitHub:https://github.com/AnJiaoDe/StatusNavigationTransparent 5 | 6 | 使用方法 7 | 8 | 注意:如果轮子死活下载不下来,说明maven地址有毛病,你需要找到jitpack的官网首页,查看最新的官网地址 9 | 10 | 注意:记得去gayhub查看最新版本,最新版本最niubility 11 | 12 | 首先创建全局theme继承Theme.AppCompat.Light.NoActionBar 13 | 14 | 然后继承StatusNavigationActivity 15 | 16 | 1. 系统StatusBar填充界面,自定义背景颜色(文字、icon颜色根据StatusBar颜色亮度设置为黑色) 17 | 18 | 2.系统StatusBar填充界面,自定义背景颜色(文字、icon颜色根据StatusBar颜色亮度设置为白色) 19 | 20 | 3.系统StatusBar不填充界面,布局添加StatusBarView实现半透明 21 | 22 | 4.系统StatusBar不填充界面,且半透明于图片之上 23 | 24 | 5.系统StatusBar不填充界面,且全透明于图片之上 25 | 26 | 6.系统navigationbar填充界面,自定义颜色 27 | 28 | 7.系统navigationbar不填充界面,且全透明 29 | 30 | 8.隐藏statusbar 31 | 32 | 9.隐藏navigationbar 33 | 34 | 10.隐藏statusbar、navigationbar,全屏 35 | 36 | 11.图片预览,切换statusbar、navigationbar的显示 37 | 38 | StatusNavigationUtils工具类 39 | 40 | StatusNavigationActivity 41 | 42 | StatusBarView和系统StatusBar高度一致 43 | 44 | NavigationBarView系统NavigationBarView高度一致 45 | 46 | ScreenUtils 47 | 48 | 欢迎联系、指正、批评 49 | 50 | ## [GitHub:https://github.com/AnJiaoDe/StatusNavigationTransparent](https://github.com/AnJiaoDe/StatusNavigationTransparent) 51 | 52 | ## 使用方法 53 | 1.工程目录下的`build.gradle`中添加代码: 54 | ## 注意:如果轮子死活下载不下来,说明maven地址有毛病,你需要找到jitpack的官网首页,查看最新的官网地址 55 | 56 | ```java 57 | allprojects { 58 | repositories { 59 | maven { url 'https://www.jitpack.io' } 60 | } 61 | } 62 | ``` 63 | 2.直接在需要使用的模块的build.gradle中添加代码: 64 | 65 | ## 注意:记得去gayhub查看最新版本,最新版本最niubility 66 | 67 | ```java 68 | dependencies { 69 | implementation 'com.github.AnJiaoDe:StatusNavigationTransparent:V1.2.4' 70 | } 71 | ``` 72 | 73 | 74 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20201006004830409.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2NvbmZ1c2luZ19hd2FrZW5pbmc=,size_16,color_FFFFFF,t_70) 75 | 76 | 77 | ## 首先创建全局theme继承Theme.AppCompat.Light.NoActionBar 78 | 79 | 80 | ```xml 81 | 83 | ``` 84 | 85 | ```xml 86 | 92 | ``` 93 | 94 | 95 | ## 然后继承StatusNavigationActivity 96 | 注意:不一定非要继承StatusNavActivity ,可以使用StatusNavigationUtils工具类、StatusBarView和NavigationBarView 97 | 98 | 99 | 总之,方法多样灵活 100 | ## 1. 系统StatusBar填充界面,自定义背景颜色(文字、icon颜色根据StatusBar颜色亮度设置为黑色) 101 | 102 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/2020100600534638.png) 103 | 104 | 105 | ```java 106 | public class Status00Activity extends StatusNavigationActivity { 107 | 108 | @Override 109 | protected void onCreate(Bundle savedInstanceState) { 110 | super.onCreate(savedInstanceState); 111 | setContentView(R.layout.activity_status00); 112 | //此行可不写,默认就是0xfff2f2f2 113 | setStatusBarColor(getStatusBarColorDefault()); 114 | } 115 | 116 | @Override 117 | public void onClick(View v) { 118 | 119 | } 120 | } 121 | ``` 122 | 123 | 124 | ## 2.系统StatusBar填充界面,自定义背景颜色(文字、icon颜色根据StatusBar颜色亮度设置为白色) 125 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20201006005516961.png) 126 | 127 | ```java 128 | public class Status0Activity extends StatusNavigationActivity { 129 | 130 | @Override 131 | protected void onCreate(Bundle savedInstanceState) { 132 | super.onCreate(savedInstanceState); 133 | setContentView(R.layout.activity_status0); 134 | setStatusBarColor(getResources().getColor(R.color.theme)); 135 | } 136 | 137 | 138 | @Override 139 | public void onClick(View v) { 140 | 141 | } 142 | } 143 | ``` 144 | 145 | ## 3.系统StatusBar不填充界面,布局添加StatusBarView实现半透明 146 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20201006005718949.png) 147 | 148 | ```java 149 | public class Status2Activity extends StatusNavigationActivity { 150 | 151 | @Override 152 | protected void onCreate(Bundle savedInstanceState) { 153 | super.onCreate(savedInstanceState); 154 | setContentView(R.layout.activity_status2); 155 | setStatusBarNoFillAndTransParentHalf(); 156 | } 157 | 158 | 159 | @Override 160 | public void onClick(View v) { 161 | 162 | } 163 | } 164 | ``` 165 | 166 | ```xml 167 | 168 | 174 | 177 | 181 | 182 | 188 | 189 | 190 | 195 | 196 | 197 | ``` 198 | 199 | ## 4.系统StatusBar不填充界面,且半透明于图片之上 200 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20201006005825571.png) 201 | 202 | ```java 203 | public class Status5Activity extends StatusNavigationActivity { 204 | 205 | @Override 206 | protected void onCreate(Bundle savedInstanceState) { 207 | super.onCreate(savedInstanceState); 208 | setContentView(R.layout.activity_status5); 209 | setStatusBarNoFillAndTransParentHalf(); 210 | //或者写2行 211 | // setStatusBarNoFill(); 212 | // setStatusBarColor(0x33000000); 213 | } 214 | 215 | @Override 216 | public void onClick(View v) { 217 | 218 | } 219 | } 220 | ``` 221 | 222 | ## 5.系统StatusBar不填充界面,且全透明于图片之上 223 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20201006005912922.png) 224 | 225 | ```java 226 | public class Status6Activity extends StatusNavigationActivity { 227 | 228 | @Override 229 | protected void onCreate(Bundle savedInstanceState) { 230 | super.onCreate(savedInstanceState); 231 | setContentView(R.layout.activity_status6); 232 | setStatusBarNoFillAndTransParent(); 233 | } 234 | 235 | 236 | @Override 237 | public void onClick(View v) { 238 | 239 | } 240 | } 241 | ``` 242 | 243 | ## 6.系统navigationbar填充界面,自定义颜色 244 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20201006010032268.png) 245 | 246 | ```java 247 | public class Navigation0Activity extends StatusNavigationActivity { 248 | 249 | @Override 250 | protected void onCreate(Bundle savedInstanceState) { 251 | super.onCreate(savedInstanceState); 252 | setContentView(R.layout.activity_navigation0); 253 | setNavigationBarColor(0xffff0000); 254 | } 255 | 256 | @Override 257 | public void onClick(View v) { 258 | 259 | } 260 | } 261 | ``` 262 | 263 | ## 7.系统navigationbar不填充界面,且全透明 264 | 模拟器上看起来是半透明,有些手机会有阴影,不必强求,随缘即可 265 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20201006010143951.png) 266 | 267 | ```java 268 | public class Navigation2Activity extends StatusNavigationActivity { 269 | 270 | @Override 271 | protected void onCreate(Bundle savedInstanceState) { 272 | super.onCreate(savedInstanceState); 273 | setContentView(R.layout.activity_nav2); 274 | setNavigationBarTransparent(); 275 | } 276 | 277 | @Override 278 | public void onClick(View v) { 279 | 280 | } 281 | } 282 | ``` 283 | 284 | ## 8.隐藏statusbar 285 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20201006010602644.gif) 286 | 287 | ```java 288 | public class HideStatusBarActivity extends StatusNavigationActivity { 289 | 290 | @Override 291 | protected void onCreate(Bundle savedInstanceState) { 292 | super.onCreate(savedInstanceState); 293 | setContentView(R.layout.activity_hide_status_bar); 294 | setHideStatusBar(); 295 | } 296 | 297 | @Override 298 | public void onClick(View v) { 299 | 300 | } 301 | } 302 | ``` 303 | 304 | ## 9.隐藏navigationbar 305 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20201006010812251.gif) 306 | 307 | ```java 308 | public class HideNavigationBarActivity extends StatusNavigationActivity { 309 | 310 | @Override 311 | protected void onCreate(Bundle savedInstanceState) { 312 | super.onCreate(savedInstanceState); 313 | setContentView(R.layout.activity_hide_navigation_bar); 314 | setHideNavigationBar(); 315 | } 316 | 317 | @Override 318 | public void onClick(View v) { 319 | 320 | } 321 | } 322 | ``` 323 | 324 | ## 10.隐藏statusbar、navigationbar,全屏 325 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20201006010930427.gif) 326 | 327 | ```java 328 | public class FullScreenActivity extends StatusNavigationActivity { 329 | 330 | @Override 331 | protected void onCreate(Bundle savedInstanceState) { 332 | super.onCreate(savedInstanceState); 333 | setContentView(R.layout.activity_full_screen); 334 | setFullScreen(); 335 | } 336 | 337 | @Override 338 | public void onClick(View v) { 339 | 340 | } 341 | } 342 | ``` 343 | 344 | ## 11.图片预览,切换statusbar、navigationbar的显示 345 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/20201006011103788.gif) 346 | 347 | ```java 348 | public class StatusNavigationSwitchActivity extends StatusNavigationActivity { 349 | private boolean fullScreen=false; 350 | @Override 351 | protected void onCreate(Bundle savedInstanceState) { 352 | super.onCreate(savedInstanceState); 353 | setContentView(R.layout.activity_status_navigation_switch); 354 | final ViewGroup rl1=findViewById(R.id.rl1); 355 | final ViewGroup rl2=findViewById(R.id.rl2); 356 | findViewById(R.id.iv).setOnClickListener(new View.OnClickListener() { 357 | @Override 358 | public void onClick(View v) { 359 | fullScreen=!fullScreen; 360 | if(fullScreen){ 361 | rl1.setVisibility(View.GONE); 362 | rl2.setVisibility(View.GONE); 363 | setHideStatusBar(); 364 | setNavigationBarTransparent(); 365 | }else { 366 | rl1.setVisibility(View.VISIBLE); 367 | rl2.setVisibility(View.VISIBLE); 368 | setClearHideStatusBar(); 369 | setStatusBarColor(getStatusBarColorDefault()); 370 | setNavigationBarColor(getNavigationBarColorDefault()); 371 | } 372 | } 373 | }); 374 | } 375 | 376 | @Override 377 | public void onClick(View v) { 378 | 379 | } 380 | } 381 | 382 | ``` 383 | 小编提供了贼多工具方便你的使用 384 | 385 | ## StatusNavigationUtils工具类 386 | 387 | ```java 388 | package com.cy.translucentparent; 389 | 390 | import android.app.Activity; 391 | import android.graphics.Color; 392 | import android.os.Build; 393 | import android.os.ParcelUuid; 394 | import android.view.View; 395 | import android.view.Window; 396 | import android.view.WindowManager; 397 | 398 | 399 | /** 400 | * Created by lenovo on 2017/4/25. 401 | */ 402 | 403 | public class StatusNavigationUtils { 404 | 405 | 406 | /** 407 | * 状态栏自定义背景颜色,6.0以上可修改状态栏字体颜色,icon颜色 408 | * 409 | * @param activity 410 | * @param color 411 | */ 412 | public static void setStatusBarColor(Activity activity, int color) { 413 | Window window = activity.getWindow(); 414 | //去除statusbar不填充的标志 415 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 416 | int ui = window.getDecorView().getSystemUiVisibility(); 417 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 418 | if (isLightColor(color)) { 419 | ui |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; //设置状态栏中字体的颜色为黑色 420 | } else { 421 | ui &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; //设置状态栏中字体颜色为白色 422 | } 423 | } 424 | window.getDecorView().setSystemUiVisibility(ui); 425 | window.setStatusBarColor(color); 426 | } 427 | 428 | /** 429 | * 判断颜色是否为亮色 430 | * @param color 431 | * @return 432 | */ 433 | public static boolean isLightColor(int color) { 434 | double darkness = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255; 435 | if (darkness < 0.5) { 436 | return true; // It's a light color 437 | } else { 438 | return false; // It's a dark color 439 | } 440 | } 441 | 442 | /** 443 | * * 状态栏不填充,布局会填充到状态栏底部,有些手机有阴影 444 | * 445 | * @param activity 446 | */ 447 | public static void setStatusBarNoFill(Activity activity) { 448 | Window window = activity.getWindow(); 449 | int ui = window.getDecorView().getSystemUiVisibility(); 450 | ui |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; 451 | window.getDecorView().setSystemUiVisibility(ui); 452 | } 453 | 454 | /** 455 | * * 导航栏全透明,布局会填充到导航栏底部,有些手机有阴影 456 | * 457 | * @param activity 458 | */ 459 | public static void setNavigationBarTransparent(Activity activity) { 460 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); 461 | } 462 | 463 | /**设置导航栏颜色,和setNavigationBarTransparent互斥,要么选择自定义导航栏颜色,要么选择导航栏全透明 464 | * @param activity 465 | * @param color 466 | */ 467 | 468 | public static void setNavigationBarColor(Activity activity, int color) { 469 | Window window = activity.getWindow(); 470 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); 471 | int ui = window.getDecorView().getSystemUiVisibility(); 472 | window.getDecorView().setSystemUiVisibility(ui); 473 | window.setNavigationBarColor(color); 474 | } 475 | 476 | /** 477 | * 隐藏状态栏、导航栏,全屏 478 | * @param activity 479 | */ 480 | public static void setFullScreen(Activity activity) { 481 | View decorView = activity.getWindow().getDecorView(); 482 | int ui = decorView.getSystemUiVisibility(); 483 | ui |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 484 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 485 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 486 | | View.SYSTEM_UI_FLAG_FULLSCREEN 487 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; 488 | decorView.setSystemUiVisibility(ui); 489 | } 490 | /** 491 | * 去除隐藏状态栏、导航栏,全屏的标志 492 | * @param activity 493 | */ 494 | public static void setClearFullScreen(Activity activity) { 495 | View decorView = activity.getWindow().getDecorView(); 496 | int ui = decorView.getSystemUiVisibility(); 497 | ui &= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 498 | & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 499 | & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 500 | & View.SYSTEM_UI_FLAG_FULLSCREEN 501 | & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; 502 | decorView.setSystemUiVisibility(ui); 503 | } 504 | 505 | /** 506 | * 隐藏状态栏 507 | * @param activity 508 | */ 509 | public static void setHideStatusBar(Activity activity) { 510 | View decorView = activity.getWindow().getDecorView(); 511 | int ui = decorView.getSystemUiVisibility(); 512 | ui |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 513 | | View.SYSTEM_UI_FLAG_FULLSCREEN 514 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; 515 | decorView.setSystemUiVisibility(ui); 516 | } 517 | /** 518 | * 去除隐藏状态栏的标志 519 | * @param activity 520 | */ 521 | public static void setClearHideStatusBar(Activity activity) { 522 | View decorView = activity.getWindow().getDecorView(); 523 | int ui = decorView.getSystemUiVisibility(); 524 | ui &= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 525 | & View.SYSTEM_UI_FLAG_FULLSCREEN 526 | & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; 527 | decorView.setSystemUiVisibility(ui); 528 | } 529 | 530 | /** 531 | * 隐藏导航栏 532 | * @param activity 533 | */ 534 | public static void setHideNavigationBar(Activity activity) { 535 | View decorView = activity.getWindow().getDecorView(); 536 | int ui = decorView.getSystemUiVisibility(); 537 | ui |=View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; 538 | decorView.setSystemUiVisibility(ui); 539 | } 540 | /** 541 | * 去除隐藏导航栏的标志 542 | * @param activity 543 | */ 544 | public static void setClearHideNavigationBar(Activity activity) { 545 | View decorView = activity.getWindow().getDecorView(); 546 | int ui = decorView.getSystemUiVisibility(); 547 | ui &=View.SYSTEM_UI_FLAG_HIDE_NAVIGATION & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; 548 | decorView.setSystemUiVisibility(ui); 549 | } 550 | } 551 | 552 | ``` 553 | 554 | ## StatusNavigationActivity 555 | 556 | ```java 557 | package com.cy.translucentparent; 558 | 559 | import android.app.Activity; 560 | import android.os.Bundle; 561 | import android.view.View; 562 | 563 | import androidx.annotation.Nullable; 564 | import androidx.appcompat.app.AppCompatActivity; 565 | 566 | 567 | /** 568 | * Created by lenovo on 2017/4/25. 569 | */ 570 | 571 | public abstract class StatusNavigationActivity extends AppCompatActivity implements View.OnClickListener { 572 | 573 | @Override 574 | protected void onCreate(@Nullable Bundle savedInstanceState) { 575 | super.onCreate(savedInstanceState); 576 | StatusNavigationUtils.setStatusBarColor(this, getStatusBarColorDefault()); 577 | StatusNavigationUtils.setNavigationBarColor(this, getNavigationBarColorDefault()); 578 | } 579 | public int getStatusBarColorDefault(){ 580 | return 0xfff2f2f2; 581 | } 582 | public int getNavigationBarColorDefault(){ 583 | return 0xff000000; 584 | } 585 | 586 | public void setStatusBarColor(int color) { 587 | StatusNavigationUtils.setStatusBarColor(this, color); 588 | } 589 | public void setNavigationBarColor(int color) { 590 | StatusNavigationUtils.setNavigationBarColor(this, color); 591 | } 592 | 593 | public void setFullScreen() { 594 | StatusNavigationUtils.setFullScreen(this); 595 | } 596 | public void setClearFullScreen() { 597 | StatusNavigationUtils.setClearFullScreen(this); 598 | } 599 | 600 | public void setHideStatusBar() { 601 | StatusNavigationUtils.setHideStatusBar(this); 602 | } 603 | public void setClearHideStatusBar() { 604 | StatusNavigationUtils.setClearHideStatusBar(this); 605 | } 606 | 607 | public void setHideNavigationBar() { 608 | StatusNavigationUtils.setHideNavigationBar(this); 609 | } 610 | public void setClearHideNavigationBar() { 611 | StatusNavigationUtils.setClearHideNavigationBar(this); 612 | } 613 | 614 | public void setStatusBarNoFill() { 615 | StatusNavigationUtils.setStatusBarNoFill(this); 616 | } 617 | 618 | public void setStatusBarNoFillAndTransParent() { 619 | setStatusBarNoFill(); 620 | setStatusBarColor(0x00000000); 621 | } 622 | 623 | public void setStatusBarNoFillAndTransParentHalf() { 624 | setStatusBarNoFill(); 625 | setStatusBarColor(0x33000000); 626 | } 627 | 628 | public void setNavigationBarTransparent() { 629 | StatusNavigationUtils.setNavigationBarTransparent(this); 630 | } 631 | } 632 | 633 | ``` 634 | 635 | ## StatusBarView和系统StatusBar高度一致 636 | 637 | ```java 638 | package com.cy.translucentparent; 639 | 640 | import android.content.Context; 641 | import android.util.AttributeSet; 642 | import android.view.View; 643 | 644 | 645 | 646 | /** 647 | * Created by lenovo on 2017/7/4. 648 | */ 649 | 650 | public class StatusBarView extends View { 651 | private Context context; 652 | public StatusBarView(Context context) { 653 | this(context,null); 654 | } 655 | 656 | public StatusBarView(Context context, AttributeSet attrs) { 657 | super(context, attrs); 658 | this.context=context; 659 | 660 | } 661 | 662 | @Override 663 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 664 | 665 | super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(ScreenUtils.getStatusBarHeight(context), MeasureSpec.EXACTLY)); 666 | } 667 | } 668 | 669 | ``` 670 | 671 | ## NavigationBarView系统NavigationBarView高度一致 672 | 673 | ```java 674 | package com.cy.translucentparent; 675 | 676 | import android.content.Context; 677 | import android.util.AttributeSet; 678 | import android.view.View; 679 | 680 | 681 | /** 682 | * Created by lenovo on 2017/7/4. 683 | */ 684 | 685 | public class NavigationBarView extends View { 686 | private Context context; 687 | public NavigationBarView(Context context) { 688 | this(context,null); 689 | } 690 | 691 | public NavigationBarView(Context context, AttributeSet attrs) { 692 | super(context, attrs); 693 | this.context=context; 694 | 695 | } 696 | 697 | @Override 698 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 699 | super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(ScreenUtils.getNavigationBarHeight(context), MeasureSpec.EXACTLY)); 700 | } 701 | } 702 | 703 | ``` 704 | 705 | ## ScreenUtils 706 | 707 | ```java 708 | package com.cy.translucentparent; 709 | 710 | import android.app.Activity; 711 | import android.content.Context; 712 | import android.content.res.Resources; 713 | import android.graphics.Rect; 714 | import android.graphics.RectF; 715 | import android.os.Build; 716 | import android.util.DisplayMetrics; 717 | import android.view.MotionEvent; 718 | import android.view.View; 719 | import android.view.WindowManager; 720 | 721 | import java.lang.reflect.Method; 722 | 723 | /** 724 | * Created by Administrator on 2018/11/20 0020. 725 | */ 726 | 727 | public class ScreenUtils { 728 | 729 | public static int getStatusBarHeight(Context context) { 730 | Resources resources = context.getResources(); 731 | int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android"); 732 | return resources.getDimensionPixelSize(resourceId); 733 | } 734 | 735 | public static int getNavigationBarHeight(Context context) { 736 | Resources resources = context.getResources(); 737 | int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); 738 | return resources.getDimensionPixelSize(resourceId); 739 | } 740 | 741 | public static int getScreenWidth(Context context) { 742 | 743 | DisplayMetrics displayMetrics = new DisplayMetrics(); 744 | 745 | WindowManager wm = (WindowManager) context.getSystemService("window"); 746 | if (Build.VERSION.SDK_INT <= 17) { 747 | wm.getDefaultDisplay().getMetrics(displayMetrics); 748 | } else { 749 | wm.getDefaultDisplay().getRealMetrics(displayMetrics); 750 | } 751 | return displayMetrics.widthPixels; 752 | } 753 | 754 | public static int getScreenHeight(Context context) { 755 | DisplayMetrics displayMetrics = new DisplayMetrics(); 756 | 757 | WindowManager wm = (WindowManager) context.getSystemService("window"); 758 | if (Build.VERSION.SDK_INT <= 17) { 759 | wm.getDefaultDisplay().getMetrics(displayMetrics); 760 | } else { 761 | wm.getDefaultDisplay().getRealMetrics(displayMetrics); 762 | } 763 | return displayMetrics.heightPixels; 764 | } 765 | 766 | public static int setYStart(Context context, float y) { 767 | 768 | // if (isGroove(context)) { 769 | 770 | return (int) (y * getScreenHeight(context)) + getStatusBarHeight(context); 771 | // } else { 772 | // return (int) (y * getScreenHeight(context)); 773 | // 774 | // 775 | // } 776 | } 777 | 778 | /** 779 | * 获取当前界面可视区域的高度 780 | * 781 | * @param activity 782 | * @return 783 | */ 784 | public static int getVisibleFrameHeight(Activity activity) { 785 | Rect r = new Rect(); 786 | //获取当前界面可视部分 787 | activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(r); 788 | 789 | // if (isGroove(activity)) { 790 | 791 | // return r.bottom - r.top - getStatusBarHeight(activity); 792 | // } else { 793 | return r.bottom - r.top; 794 | // 795 | // } 796 | } 797 | 798 | /** 799 | * 获取当前界面可视区域的宽度 800 | * 801 | * @param activity 802 | * @return 803 | */ 804 | public static int getVisibleFrameWidth(Activity activity) { 805 | Rect r = new Rect(); 806 | //获取当前界面可视部分 807 | activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(r); 808 | return r.right - r.left; 809 | } 810 | } 811 | 812 | 813 | ``` 814 | 815 | ## 欢迎联系、指正、批评 816 | 817 | 818 | 819 | Github:[https://github.com/AnJiaoDe](https://github.com/AnJiaoDe) 820 | 821 | 简书:[https://www.jianshu.com/u/b8159d455c69](https://www.jianshu.com/u/b8159d455c69) 822 | 823 | CSDN:[https://blog.csdn.net/confusing_awakening](https://blog.csdn.net/confusing_awakening) 824 | 825 | ffmpeg入门教程:[https://www.jianshu.com/p/042c7847bd8a](https://www.jianshu.com/p/042c7847bd8a) 826 | 827 | 微信公众号 828 | ![这里写图片描述](https://imgconvert.csdnimg.cn/aHR0cDovL3VwbG9hZC1pbWFnZXMuamlhbnNodS5pby91cGxvYWRfaW1hZ2VzLzExODY2MDc4LWZjZmJiNDUxNzVmOTlkZTA) 829 | 830 | QQ群 831 | 832 | ![这里写图片描述](https://imgconvert.csdnimg.cn/aHR0cDovL3VwbG9hZC1pbWFnZXMuamlhbnNodS5pby91cGxvYWRfaW1hZ2VzLzExODY2MDc4LWEzMWZmNDBhYzY4NTBhNmQ) 833 | 834 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion var.compileSdkVersion 5 | 6 | defaultConfig { 7 | minSdkVersion var.minSdkVersion 8 | targetSdkVersion var.targetSdkVersion 9 | applicationId "com.cy.statusnavigationtrans" 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | //指定jdk版本 21 | compileOptions { 22 | sourceCompatibility JavaVersion.VERSION_1_8 23 | targetCompatibility JavaVersion.VERSION_1_8 24 | } 25 | } 26 | configurations.all { 27 | resolutionStrategy { 28 | resolutionStrategy.eachDependency { details -> 29 | if (details.requested.group == 'androidx.appcompat') { 30 | details.useVersion "1.1.0" 31 | } 32 | } 33 | } 34 | } 35 | dependencies { 36 | implementation fileTree(dir: 'libs', include: ['*.jar']) 37 | implementation 'androidx.appcompat:appcompat:+' 38 | api project(':translucentparent') 39 | } 40 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\AndroidSDK/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/cy/statusnavigationtrans/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.cy.statusnavigationtrans; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.cy.statusnavigationtrans", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/cy/statusnavigationtrans/FullScreenActivity.java: -------------------------------------------------------------------------------- 1 | package com.cy.statusnavigationtrans; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | 6 | import com.cy.translucentparent.StatusNavigationActivity; 7 | 8 | public class FullScreenActivity extends StatusNavigationActivity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_full_screen); 14 | setFullScreen(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/cy/statusnavigationtrans/HideNavigationBarActivity.java: -------------------------------------------------------------------------------- 1 | package com.cy.statusnavigationtrans; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | 6 | import com.cy.translucentparent.StatusNavigationActivity; 7 | 8 | public class HideNavigationBarActivity extends StatusNavigationActivity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_hide_navigation_bar); 14 | setHideNavigationBar(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/cy/statusnavigationtrans/HideStatusBarActivity.java: -------------------------------------------------------------------------------- 1 | package com.cy.statusnavigationtrans; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | 6 | import com.cy.translucentparent.StatusNavigationActivity; 7 | 8 | public class HideStatusBarActivity extends StatusNavigationActivity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_hide_status_bar); 14 | setHideStatusBar(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/cy/statusnavigationtrans/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.cy.statusnavigationtrans; 2 | 3 | import android.content.Intent; 4 | import android.graphics.Color; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | 8 | import com.cy.translucentparent.StatusNavigationActivity; 9 | 10 | public class MainActivity extends StatusNavigationActivity implements View.OnClickListener { 11 | 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setNavigationBarColor(Color.BLACK); 16 | setContentView(R.layout.activity_main); 17 | findViewById(R.id.btn_00).setOnClickListener(this); 18 | findViewById(R.id.btn_0).setOnClickListener(this); 19 | findViewById(R.id.btn_2).setOnClickListener(this); 20 | findViewById(R.id.btn_5).setOnClickListener(this); 21 | findViewById(R.id.btn_6).setOnClickListener(this); 22 | findViewById(R.id.btn_7).setOnClickListener(this); 23 | // findViewById(R.id.btn_8).setOnClickListener(this); 24 | findViewById(R.id.btn_9).setOnClickListener(this); 25 | findViewById(R.id.btn_10).setOnClickListener(this); 26 | findViewById(R.id.btn_11).setOnClickListener(this); 27 | findViewById(R.id.btn_12).setOnClickListener(this); 28 | findViewById(R.id.btn_13).setOnClickListener(this); 29 | // StatusNavigationUtils.setStatusBarColor(this, getResources().getColor(R.color.colorPrimary)); 30 | setStatusBarColor(getResources().getColor(R.color.theme)); 31 | } 32 | 33 | @Override 34 | public void onClick(View v) { 35 | switch (v.getId()) { 36 | case R.id.btn_00: 37 | startActivity(new Intent(this,Status00Activity.class)); 38 | break; 39 | case R.id.btn_0: 40 | startActivity(new Intent(this,Status0Activity.class)); 41 | break; 42 | case R.id.btn_2: 43 | startActivity(new Intent(this,Status2Activity.class)); 44 | break; 45 | case R.id.btn_5: 46 | startActivity(new Intent(this,Status5Activity.class)); 47 | break; 48 | case R.id.btn_6: 49 | startActivity(new Intent(this,Status6Activity.class)); 50 | break; 51 | case R.id.btn_7: 52 | startActivity(new Intent(this,Navigation0Activity.class)); 53 | break; 54 | // case R.id.btn_8: 55 | // startActivity(new Intent(this,Navigation1Activity.class)); 56 | // break; 57 | case R.id.btn_9: 58 | startActivity(new Intent(this,Navigation2Activity.class)); 59 | break; 60 | case R.id.btn_10: 61 | startActivity(new Intent(this,HideStatusBarActivity.class)); 62 | break; 63 | case R.id.btn_11: 64 | startActivity(new Intent(this,HideNavigationBarActivity.class)); 65 | break; 66 | case R.id.btn_12: 67 | startActivity(new Intent(this,FullScreenActivity.class)); 68 | break; 69 | case R.id.btn_13: 70 | startActivity(new Intent(this,StatusNavigationSwitchActivity.class)); 71 | break; 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /app/src/main/java/com/cy/statusnavigationtrans/Navigation0Activity.java: -------------------------------------------------------------------------------- 1 | package com.cy.statusnavigationtrans; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | 6 | import com.cy.translucentparent.StatusNavigationActivity; 7 | 8 | public class Navigation0Activity extends StatusNavigationActivity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_navigation0); 14 | setNavigationBarColor(0xffff0000); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/cy/statusnavigationtrans/Navigation1Activity.java: -------------------------------------------------------------------------------- 1 | //package com.cy.statusnavigationtrans; 2 | // 3 | //import android.os.Bundle; 4 | //import android.view.View; 5 | // 6 | //import com.cy.translucentparent.StatusNavigationActivity; 7 | // 8 | //public class Navigation1Activity extends StatusNavigationActivity { 9 | // 10 | // @Override 11 | // protected void onCreate(Bundle savedInstanceState) { 12 | // super.onCreate(savedInstanceState); 13 | // setContentView(R.layout.activity_nav1); 14 | //// setStatusBarColor(0x00000000); 15 | // setNavigationBarTransparent(); 16 | // setNavigationBarColor(0x33000000); 17 | // } 18 | // 19 | // 20 | // 21 | // @Override 22 | // public void onClick(View v) { 23 | // 24 | // } 25 | //} 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/cy/statusnavigationtrans/Navigation2Activity.java: -------------------------------------------------------------------------------- 1 | package com.cy.statusnavigationtrans; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | 6 | import androidx.appcompat.app.AppCompatActivity; 7 | 8 | import com.cy.translucentparent.StatusNavigationActivity; 9 | import com.cy.translucentparent.StatusNavigationUtils; 10 | 11 | public class Navigation2Activity extends StatusNavigationActivity { 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_nav2); 17 | setNavigationBarTransparent(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/cy/statusnavigationtrans/Status00Activity.java: -------------------------------------------------------------------------------- 1 | package com.cy.statusnavigationtrans; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | 6 | import com.cy.translucentparent.StatusNavigationActivity; 7 | 8 | public class Status00Activity extends StatusNavigationActivity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_status00); 14 | //此行可不写,默认就是0xfff2f2f2 15 | setStatusBarColor(getStatusBarColorDefault()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/cy/statusnavigationtrans/Status0Activity.java: -------------------------------------------------------------------------------- 1 | package com.cy.statusnavigationtrans; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | 6 | import com.cy.translucentparent.StatusNavigationActivity; 7 | 8 | public class Status0Activity extends StatusNavigationActivity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_status0); 14 | setStatusBarColor(getResources().getColor(R.color.theme)); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/cy/statusnavigationtrans/Status2Activity.java: -------------------------------------------------------------------------------- 1 | package com.cy.statusnavigationtrans; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | 6 | import androidx.core.view.ViewCompat; 7 | 8 | import com.cy.translucentparent.StatusNavigationActivity; 9 | 10 | public class Status2Activity extends StatusNavigationActivity { 11 | 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.activity_status2); 16 | setStatusBarNoFillAndTransParentHalf(); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/cy/statusnavigationtrans/Status5Activity.java: -------------------------------------------------------------------------------- 1 | package com.cy.statusnavigationtrans; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | 6 | import com.cy.translucentparent.StatusNavigationActivity; 7 | 8 | public class Status5Activity extends StatusNavigationActivity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_status5); 14 | setStatusBarNoFillAndTransParentHalf(); 15 | //或者写2行 16 | // setStatusBarNoFill(); 17 | // setStatusBarColor(0x33000000); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/cy/statusnavigationtrans/Status6Activity.java: -------------------------------------------------------------------------------- 1 | package com.cy.statusnavigationtrans; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | 6 | import com.cy.translucentparent.StatusNavigationActivity; 7 | 8 | public class Status6Activity extends StatusNavigationActivity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_status6); 14 | setStatusBarNoFillAndTransParent(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/cy/statusnavigationtrans/StatusNavigationSwitchActivity.java: -------------------------------------------------------------------------------- 1 | package com.cy.statusnavigationtrans; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import com.cy.translucentparent.StatusNavigationActivity; 10 | 11 | public class StatusNavigationSwitchActivity extends StatusNavigationActivity { 12 | private boolean fullScreen=false; 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_status_navigation_switch); 17 | final ViewGroup rl1=findViewById(R.id.rl1); 18 | final ViewGroup rl2=findViewById(R.id.rl2); 19 | findViewById(R.id.iv).setOnClickListener(new View.OnClickListener() { 20 | @Override 21 | public void onClick(View v) { 22 | fullScreen=!fullScreen; 23 | if(fullScreen){ 24 | rl1.setVisibility(View.GONE); 25 | rl2.setVisibility(View.GONE); 26 | setHideStatusBar(); 27 | setNavigationBarTransparent(); 28 | }else { 29 | rl1.setVisibility(View.VISIBLE); 30 | rl2.setVisibility(View.VISIBLE); 31 | setClearHideStatusBar(); 32 | setStatusBarColor(getStatusBarColorDefault()); 33 | setNavigationBarColor(getNavigationBarColorDefault()); 34 | } 35 | } 36 | }); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnJiaoDe/StatusNavigationTransparent/69943ef8fc79b88eafce38ce0ceb8e843b5e0baa/app/src/main/res/drawable-xhdpi/back.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/huge.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnJiaoDe/StatusNavigationTransparent/69943ef8fc79b88eafce38ce0ceb8e843b5e0baa/app/src/main/res/drawable-xhdpi/huge.jpg -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_full_screen.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_hide_navigation_bar.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_hide_status_bar.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 |