├── .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 |
6 |
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 |
8 |
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 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
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 | 
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 | 
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 | 
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 | 
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 | 
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 | 
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 | 
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 | 
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 | 
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 | 
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 | 
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 | 
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 | 
829 |
830 | QQ群
831 |
832 | 
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 |
19 |
20 |
25 |
26 |
31 |
32 |
37 |
38 |
43 |
44 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
60 |
65 |
70 |
75 |
80 |
81 |
82 |
83 |
84 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_nav1.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_nav2.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_navigation0.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_status0.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_status00.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_status2.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
15 |
16 |
22 |
23 |
24 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_status5.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
13 |
14 |
18 |
19 |
25 |
26 |
27 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_status6.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
19 |
20 |
26 |
27 |
28 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_status_navigation_switch.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
20 |
21 |
27 |
28 |
34 |
35 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AnJiaoDe/StatusNavigationTransparent/69943ef8fc79b88eafce38ce0ceb8e843b5e0baa/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AnJiaoDe/StatusNavigationTransparent/69943ef8fc79b88eafce38ce0ceb8e843b5e0baa/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AnJiaoDe/StatusNavigationTransparent/69943ef8fc79b88eafce38ce0ceb8e843b5e0baa/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AnJiaoDe/StatusNavigationTransparent/69943ef8fc79b88eafce38ce0ceb8e843b5e0baa/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AnJiaoDe/StatusNavigationTransparent/69943ef8fc79b88eafce38ce0ceb8e843b5e0baa/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #3F51B5
5 | #303F9F
6 | #FF4081
7 |
8 |
9 | #ffffff
10 | #e6e6e6
11 | #00000000
12 | #66000000
13 | #20000000
14 |
15 | #333333
16 | #fb484c
17 | #77fb484c
18 | #11fb484c
19 | #eaebed
20 | #343434
21 | #999999
22 | #55999999
23 | #99000000
24 | #ffff00
25 | #22ffffff
26 |
27 |
28 | #2a5caa
29 |
30 | #2a5caa
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 20dp
5 | 16dp
6 | 48dp
7 | 56dp
8 | 56dp
9 | 10dp
10 | 20dp
11 | 30dp
12 | 40dp
13 | 50dp
14 | 22sp
15 | 18sp
16 | 17sp
17 | 16sp
18 | 15sp
19 | 14sp
20 | 13sp
21 | 12sp
22 | 11sp
23 | 10sp
24 | 9sp
25 | 8sp
26 | 7sp
27 | 6sp
28 | 5sp
29 | 5dp
30 | 1dp
31 | 60dp
32 | 40dp
33 | 90dp
34 | 5dp
35 | 24dp
36 | 60dp
37 | 100dp
38 | 150dp
39 | 180dp
40 | 260dp
41 |
42 |
43 | 12dp
44 | 10dp
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | StatusNavigationTrans
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/test/java/com/cy/statusnavigationtrans/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.cy.statusnavigationtrans;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 |
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:3.4.0'
12 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
13 |
14 |
15 | // NOTE: Do not place your application dependencies here; they belong
16 | // in the individual module build.gradle files
17 | }
18 | }
19 |
20 | allprojects {
21 | repositories {
22 | google()
23 | jcenter()
24 | maven { url 'https://jitpack.io' }
25 | }
26 | }
27 |
28 | task clean(type: Delete) {
29 | delete rootProject.buildDir
30 | }
31 | ext {
32 | var = [
33 | minSdkVersion : 21,
34 | targetSdkVersion : 30,
35 | compileSdkVersion: 30,
36 | buildToolsVersion: "30.0.3"
37 | ]
38 | minifyEnabled = false
39 | zipAlignEnabled = false
40 | }
--------------------------------------------------------------------------------
/gif/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AnJiaoDe/StatusNavigationTransparent/69943ef8fc79b88eafce38ce0ceb8e843b5e0baa/gif/1.png
--------------------------------------------------------------------------------
/gif/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AnJiaoDe/StatusNavigationTransparent/69943ef8fc79b88eafce38ce0ceb8e843b5e0baa/gif/2.png
--------------------------------------------------------------------------------
/gif/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AnJiaoDe/StatusNavigationTransparent/69943ef8fc79b88eafce38ce0ceb8e843b5e0baa/gif/3.png
--------------------------------------------------------------------------------
/gif/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AnJiaoDe/StatusNavigationTransparent/69943ef8fc79b88eafce38ce0ceb8e843b5e0baa/gif/4.png
--------------------------------------------------------------------------------
/gif/5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AnJiaoDe/StatusNavigationTransparent/69943ef8fc79b88eafce38ce0ceb8e843b5e0baa/gif/5.png
--------------------------------------------------------------------------------
/gif/6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AnJiaoDe/StatusNavigationTransparent/69943ef8fc79b88eafce38ce0ceb8e843b5e0baa/gif/6.png
--------------------------------------------------------------------------------
/gif/7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AnJiaoDe/StatusNavigationTransparent/69943ef8fc79b88eafce38ce0ceb8e843b5e0baa/gif/7.png
--------------------------------------------------------------------------------
/gif/8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AnJiaoDe/StatusNavigationTransparent/69943ef8fc79b88eafce38ce0ceb8e843b5e0baa/gif/8.png
--------------------------------------------------------------------------------
/gif/9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AnJiaoDe/StatusNavigationTransparent/69943ef8fc79b88eafce38ce0ceb8e843b5e0baa/gif/9.png
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | android.injected.testOnly=false
21 |
22 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AnJiaoDe/StatusNavigationTransparent/69943ef8fc79b88eafce38ce0ceb8e843b5e0baa/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed May 13 17:12:18 CST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':translucentparent'
2 |
--------------------------------------------------------------------------------
/translucentparent/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/translucentparent/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 |
4 | android {
5 | compileSdkVersion var.compileSdkVersion
6 |
7 | defaultConfig {
8 | minSdkVersion var.minSdkVersion
9 | targetSdkVersion var.targetSdkVersion
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 | //---------------------------------------------下面的必加,加上下面的作用是在上传后会带上注释,不然会发现没有注释
24 | // 打包源码
25 | task sourcesJar(type: Jar) {
26 | from android.sourceSets.main.java.srcDirs
27 | classifier = 'sources'
28 | }
29 | artifacts {
30 | archives sourcesJar
31 | }
32 |
33 | dependencies {
34 | compileOnly fileTree(dir: 'libs', include: ['*.jar'])
35 | compileOnly 'androidx.appcompat:appcompat:+'
36 | }
37 |
--------------------------------------------------------------------------------
/translucentparent/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 |
--------------------------------------------------------------------------------
/translucentparent/src/androidTest/java/com/cy/translucentparent/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.cy.translucentparent;
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.translucentparent.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/translucentparent/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/translucentparent/src/main/java/com/cy/translucentparent/LogUtils.java:
--------------------------------------------------------------------------------
1 | //package com.cy.translucentparent;
2 | //
3 | //import android.util.Log;
4 | //
5 | ///**
6 | // * Created by lenovo on 2017/8/20.
7 | // */
8 | //
9 | //public class LogUtils {
10 | // private static boolean DEBUG = true;
11 | //
12 | // private LogUtils() {
13 | // }
14 | //
15 | // public static synchronized void debug(boolean debug) {
16 | // DEBUG = debug;
17 | // }
18 | //
19 | // public static void logI(Object tag, Object content) {
20 | // if(DEBUG==false)return;
21 | // if (tag == null) tag = "LOG_I";
22 | // Log.i(String.valueOf(tag), "----------------------------------->>>>" + content);
23 | // }
24 | // public static void logE(Object tag, Object content) {
25 | // if(DEBUG==false)return;
26 | // if (tag == null) tag = "LOG_E";
27 | // Log.e(String.valueOf(tag), "----------------------------------->>>>" + content);
28 | // }
29 | //
30 | //
31 | // public static void logI(Object content) {
32 | // logI(null,content);
33 | // }
34 | // public static void logE(Object content) {
35 | // logE(null,content);
36 | // }
37 | //
38 | // public static void log(Object tag, Object content) {
39 | // logE(tag,content);
40 | // }
41 | // public static void log(Object content) {
42 | // logE(content);
43 | // }
44 | //}
45 |
--------------------------------------------------------------------------------
/translucentparent/src/main/java/com/cy/translucentparent/NavigationBarView.java:
--------------------------------------------------------------------------------
1 | package com.cy.translucentparent;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 |
7 |
8 | /**
9 | * Created by lenovo on 2017/7/4.
10 | */
11 |
12 | public class NavigationBarView extends View {
13 | private Context context;
14 | public NavigationBarView(Context context) {
15 | this(context,null);
16 | }
17 |
18 | public NavigationBarView(Context context, AttributeSet attrs) {
19 | super(context, attrs);
20 | this.context=context;
21 |
22 | }
23 |
24 | @Override
25 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
26 | super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(ScreenUtils.getNavigationBarHeight(context), MeasureSpec.EXACTLY));
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/translucentparent/src/main/java/com/cy/translucentparent/ScreenUtils.java:
--------------------------------------------------------------------------------
1 | package com.cy.translucentparent;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.res.Resources;
6 | import android.graphics.Rect;
7 | import android.graphics.RectF;
8 | import android.os.Build;
9 | import android.util.DisplayMetrics;
10 | import android.view.MotionEvent;
11 | import android.view.View;
12 | import android.view.WindowManager;
13 |
14 | import java.lang.reflect.Method;
15 |
16 | /**
17 | * Created by Administrator on 2018/11/20 0020.
18 | */
19 |
20 | public class ScreenUtils {
21 |
22 | public static int getStatusBarHeight(Context context) {
23 | Resources resources = context.getResources();
24 | int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
25 | return resources.getDimensionPixelSize(resourceId);
26 | }
27 |
28 | public static int getNavigationBarHeight(Context context) {
29 | Resources resources = context.getResources();
30 | int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
31 | return resources.getDimensionPixelSize(resourceId);
32 | }
33 |
34 | public static int getScreenWidth(Context context) {
35 |
36 | DisplayMetrics displayMetrics = new DisplayMetrics();
37 |
38 | WindowManager wm = (WindowManager) context.getSystemService("window");
39 | if (Build.VERSION.SDK_INT <= 17) {
40 | wm.getDefaultDisplay().getMetrics(displayMetrics);
41 | } else {
42 | wm.getDefaultDisplay().getRealMetrics(displayMetrics);
43 | }
44 | return displayMetrics.widthPixels;
45 | }
46 |
47 | public static int getScreenHeight(Context context) {
48 | DisplayMetrics displayMetrics = new DisplayMetrics();
49 |
50 | WindowManager wm = (WindowManager) context.getSystemService("window");
51 | if (Build.VERSION.SDK_INT <= 17) {
52 | wm.getDefaultDisplay().getMetrics(displayMetrics);
53 | } else {
54 | wm.getDefaultDisplay().getRealMetrics(displayMetrics);
55 | }
56 | return displayMetrics.heightPixels;
57 | }
58 |
59 | public static int setYStart(Context context, float y) {
60 |
61 | // if (isGroove(context)) {
62 |
63 | return (int) (y * getScreenHeight(context)) + getStatusBarHeight(context);
64 | // } else {
65 | // return (int) (y * getScreenHeight(context));
66 | //
67 | //
68 | // }
69 | }
70 |
71 | /**
72 | * 获取当前界面可视区域的高度
73 | *
74 | * @param activity
75 | * @return
76 | */
77 | public static int getVisibleFrameHeight(Activity activity) {
78 | Rect r = new Rect();
79 | //获取当前界面可视部分
80 | activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
81 |
82 | // if (isGroove(activity)) {
83 |
84 | // return r.bottom - r.top - getStatusBarHeight(activity);
85 | // } else {
86 | return r.bottom - r.top;
87 | //
88 | // }
89 | }
90 |
91 | /**
92 | * 获取当前界面可视区域的宽度
93 | *
94 | * @param activity
95 | * @return
96 | */
97 | public static int getVisibleFrameWidth(Activity activity) {
98 | Rect r = new Rect();
99 | //获取当前界面可视部分
100 | activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
101 | return r.right - r.left;
102 | }
103 | }
104 |
105 |
--------------------------------------------------------------------------------
/translucentparent/src/main/java/com/cy/translucentparent/StatusBarView.java:
--------------------------------------------------------------------------------
1 | package com.cy.translucentparent;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 |
7 |
8 |
9 | /**
10 | * Created by lenovo on 2017/7/4.
11 | */
12 |
13 | public class StatusBarView extends View {
14 | private Context context;
15 | public StatusBarView(Context context) {
16 | this(context,null);
17 | }
18 |
19 | public StatusBarView(Context context, AttributeSet attrs) {
20 | super(context, attrs);
21 | this.context=context;
22 |
23 | }
24 |
25 | @Override
26 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
27 |
28 | super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(ScreenUtils.getStatusBarHeight(context), MeasureSpec.EXACTLY));
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/translucentparent/src/main/java/com/cy/translucentparent/StatusNavigationActivity.java:
--------------------------------------------------------------------------------
1 | package com.cy.translucentparent;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 |
7 | import androidx.annotation.Nullable;
8 | import androidx.appcompat.app.AppCompatActivity;
9 |
10 |
11 | /**
12 | * Created by lenovo on 2017/4/25.
13 | */
14 |
15 | public abstract class StatusNavigationActivity extends AppCompatActivity {
16 |
17 | @Override
18 | protected void onCreate(@Nullable Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | StatusNavigationUtils.getInstance().setStatusBarColor(this, getStatusBarColorDefault());
21 | StatusNavigationUtils.getInstance().setNavigationBarColor(this, getNavigationBarColorDefault());
22 | }
23 | public int getStatusBarColorDefault(){
24 | return 0xffffffff;
25 | }
26 | public int getNavigationBarColorDefault(){
27 | return 0xffffffff;
28 | }
29 |
30 | public void setStatusBarColor(int color) {
31 | StatusNavigationUtils.getInstance().setStatusBarColor(this, color);
32 | }
33 | public void setNavigationBarColor(int color) {
34 | StatusNavigationUtils.getInstance().setNavigationBarColor(this, color);
35 | }
36 |
37 | public void setFullScreen() {
38 | StatusNavigationUtils.getInstance().setFullScreen(this);
39 | }
40 | public void setClearFullScreen() {
41 | StatusNavigationUtils.getInstance().setClearFullScreen(this);
42 | }
43 |
44 | public void setHideStatusBar() {
45 | StatusNavigationUtils.getInstance().setHideStatusBar(this);
46 | }
47 | public void setClearHideStatusBar() {
48 | StatusNavigationUtils.getInstance().setClearHideStatusBar(this);
49 | }
50 |
51 | public void setHideNavigationBar() {
52 | StatusNavigationUtils.getInstance().setHideNavigationBar(this);
53 | }
54 | public void setClearHideNavigationBar() {
55 | StatusNavigationUtils.getInstance().setClearHideNavigationBar(this);
56 | }
57 |
58 | public void setStatusBarNoFill() {
59 | StatusNavigationUtils.getInstance().setStatusBarNoFill(this);
60 | }
61 |
62 | public void setStatusBarNoFillAndTransParent() {
63 | setStatusBarNoFill();
64 | setStatusBarColor(0x00000000);
65 | }
66 |
67 | public void setStatusBarNoFillAndTransParentHalf() {
68 | setStatusBarNoFill();
69 | setStatusBarColor(0x33000000);
70 | }
71 |
72 | public void setNavigationBarTransparent() {
73 | StatusNavigationUtils.getInstance().setNavigationBarTransparent(this);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/translucentparent/src/main/java/com/cy/translucentparent/StatusNavigationUtils.java:
--------------------------------------------------------------------------------
1 | package com.cy.translucentparent;
2 |
3 | import android.app.Activity;
4 | import android.graphics.Color;
5 | import android.os.Build;
6 | import android.view.View;
7 | import android.view.ViewTreeObserver;
8 | import android.view.Window;
9 | import android.view.WindowManager;
10 |
11 | import androidx.annotation.RequiresApi;
12 |
13 | import java.util.HashMap;
14 | import java.util.Map;
15 |
16 |
17 | /**
18 | * Created by lenovo on 2017/4/25.
19 | */
20 |
21 | public class StatusNavigationUtils {
22 | private Map mapFocusListener;
23 | private Map mapAttachListener;
24 | private Map mapHideStatusBar;
25 | private Map mapHideNavigationBar;
26 | private Map mapFullScreen;
27 |
28 | private StatusNavigationUtils() {
29 | mapFocusListener = new HashMap<>();
30 | mapAttachListener = new HashMap<>();
31 | mapHideStatusBar = new HashMap<>();
32 | mapHideNavigationBar = new HashMap<>();
33 | mapFullScreen = new HashMap<>();
34 | }
35 |
36 | private static class StatusNavigationUtilsHolder {
37 | private static StatusNavigationUtils instance = new StatusNavigationUtils();
38 | }
39 |
40 | public static StatusNavigationUtils getInstance() {
41 | return StatusNavigationUtilsHolder.instance;
42 | }
43 |
44 | private String getKey(Object obj) {
45 | return obj.getClass().getName() + obj.hashCode();
46 | }
47 |
48 | /**
49 | * 状态栏自定义背景颜色,6.0以上可修改状态栏字体颜色,icon颜色
50 | *
51 | * @param activity
52 | * @param color
53 | */
54 | public void setStatusBarColor(Activity activity, int color) {
55 | Window window = activity.getWindow();
56 | //去除statusbar不填充的标志
57 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
58 | int ui = window.getDecorView().getSystemUiVisibility();
59 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
60 | if (isLightColor(color)) {
61 | ui |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; //设置状态栏中字体的颜色为黑色
62 | } else {
63 | ui &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; //设置状态栏中字体颜色为白色
64 | }
65 | }
66 | window.getDecorView().setSystemUiVisibility(ui);
67 | window.setStatusBarColor(color);
68 | }
69 |
70 | /**
71 | * 判断颜色是否为亮色
72 | *
73 | * @param color
74 | * @return
75 | */
76 | public boolean isLightColor(int color) {
77 | double darkness = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255;
78 | if (darkness < 0.5) {
79 | return true; // It's a light color
80 | } else {
81 | return false; // It's a dark color
82 | }
83 | }
84 |
85 | /**
86 | * * 状态栏不填充,布局会填充到状态栏底部,有些手机有阴影
87 | *
88 | * @param activity
89 | */
90 | public void setStatusBarNoFill(Activity activity) {
91 | Window window = activity.getWindow();
92 | int ui = window.getDecorView().getSystemUiVisibility();
93 | ui |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
94 | window.getDecorView().setSystemUiVisibility(ui);
95 | }
96 |
97 | /**
98 | * * 导航栏全透明,布局会填充到导航栏底部,有些手机有阴影
99 | *
100 | * @param activity
101 | */
102 | public void setNavigationBarTransparent(Activity activity) {
103 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
104 | }
105 |
106 | /**
107 | * 设置导航栏颜色,和setNavigationBarTransparent互斥,要么选择自定义导航栏颜色,要么选择导航栏全透明
108 | *
109 | * @param activity
110 | * @param color
111 | */
112 |
113 | public void setNavigationBarColor(Activity activity, int color) {
114 | Window window = activity.getWindow();
115 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
116 | int ui = window.getDecorView().getSystemUiVisibility();
117 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
118 | if (isLightColor(color)) {
119 | ui |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; //设置导航栏中字体的颜色为黑色
120 | } else {
121 | ui &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; //设置导航栏中字体颜色为白色
122 | }
123 | }
124 | window.getDecorView().setSystemUiVisibility(ui);
125 | window.setNavigationBarColor(color);
126 | }
127 |
128 |
129 | private void addListener(final Activity activity, ViewTreeObserver.OnWindowFocusChangeListener onWindowFocusChangeListener) {
130 | View decorView = activity.getWindow().getDecorView();
131 | mapFocusListener.put(getKey(activity), onWindowFocusChangeListener);
132 | decorView.getViewTreeObserver().addOnWindowFocusChangeListener(onWindowFocusChangeListener);
133 |
134 | View.OnAttachStateChangeListener onAttachStateChangeListener = new View.OnAttachStateChangeListener() {
135 | @Override
136 | public void onViewAttachedToWindow(View v) {
137 |
138 | }
139 |
140 | @Override
141 | public void onViewDetachedFromWindow(View v) {
142 | mapFocusListener.remove(getKey(activity));
143 | mapAttachListener.remove(getKey(activity));
144 | mapHideStatusBar.remove(getKey(activity));
145 | mapHideNavigationBar.remove(getKey(activity));
146 | mapFullScreen.remove(getKey(activity));
147 | }
148 | };
149 | mapAttachListener.put(getKey(activity), onAttachStateChangeListener);
150 | decorView.addOnAttachStateChangeListener(onAttachStateChangeListener);
151 | }
152 |
153 | private void hideStatusBar(final Activity activity) {
154 | mapHideStatusBar.put(getKey(activity), true);
155 |
156 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
157 | // 设置窗口占用刘海区
158 | WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
159 | lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
160 | activity.getWindow().setAttributes(lp);
161 | }
162 |
163 | final View decorView = activity.getWindow().getDecorView();
164 | int ui = decorView.getSystemUiVisibility();
165 | ui |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
166 | | View.SYSTEM_UI_FLAG_FULLSCREEN
167 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
168 | decorView.setSystemUiVisibility(ui);
169 | }
170 |
171 | /**
172 | * 隐藏状态栏
173 | *
174 | * @param activity
175 | */
176 | public void setHideStatusBar(final Activity activity) {
177 | hideStatusBar(activity);
178 | addListener(activity, new ViewTreeObserver.OnWindowFocusChangeListener() {
179 | @Override
180 | public void onWindowFocusChanged(boolean hasFocus) {
181 | if (mapHideStatusBar.get(getKey(activity))) hideStatusBar(activity);
182 | }
183 | });
184 | }
185 |
186 | /**
187 | * 去除隐藏状态栏的标志
188 | *
189 | * @param activity
190 | */
191 | public void setClearHideStatusBar(Activity activity) {
192 | mapHideStatusBar.put(getKey(activity), false);
193 | View decorView = activity.getWindow().getDecorView();
194 | int ui = decorView.getSystemUiVisibility();
195 | ui &= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
196 | & View.SYSTEM_UI_FLAG_FULLSCREEN
197 | & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
198 | decorView.setSystemUiVisibility(ui);
199 | }
200 |
201 | private void hideNavigationBar(Activity activity) {
202 | mapHideNavigationBar.put(getKey(activity), true);
203 | View decorView = activity.getWindow().getDecorView();
204 | int ui = decorView.getSystemUiVisibility();
205 | ui |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
206 | decorView.setSystemUiVisibility(ui);
207 | }
208 |
209 | /**
210 | * 隐藏导航栏
211 | *
212 | * @param activity
213 | */
214 | public void setHideNavigationBar(final Activity activity) {
215 | hideNavigationBar(activity);
216 | addListener(activity, new ViewTreeObserver.OnWindowFocusChangeListener() {
217 | @Override
218 | public void onWindowFocusChanged(boolean hasFocus) {
219 | if (mapHideNavigationBar.get(getKey(activity))) hideNavigationBar(activity);
220 | }
221 | });
222 | }
223 |
224 | /**
225 | * 去除隐藏导航栏的标志
226 | *
227 | * @param activity
228 | */
229 | public void setClearHideNavigationBar(Activity activity) {
230 | mapHideNavigationBar.put(getKey(activity), false);
231 | View decorView = activity.getWindow().getDecorView();
232 | int ui = decorView.getSystemUiVisibility();
233 | ui &= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
234 | decorView.setSystemUiVisibility(ui);
235 | }
236 |
237 | public void fullScreen(Activity activity) {
238 | mapFullScreen.put(getKey(activity), true);
239 |
240 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
241 | // 设置窗口占用刘海区
242 | WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
243 | lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
244 | activity.getWindow().setAttributes(lp);
245 | }
246 |
247 | View decorView = activity.getWindow().getDecorView();
248 | int ui = decorView.getSystemUiVisibility();
249 | ui |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
250 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
251 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
252 | | View.SYSTEM_UI_FLAG_FULLSCREEN
253 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
254 | decorView.setSystemUiVisibility(ui);
255 | }
256 |
257 | /**
258 | * 隐藏状态栏、导航栏,全屏
259 | *
260 | * @param activity
261 | */
262 | public void setFullScreen(final Activity activity) {
263 | fullScreen(activity);
264 | addListener(activity, new ViewTreeObserver.OnWindowFocusChangeListener() {
265 | @Override
266 | public void onWindowFocusChanged(boolean hasFocus) {
267 | if (mapFullScreen.get(getKey(activity))) fullScreen(activity);
268 | }
269 | });
270 | }
271 |
272 | /**
273 | * 去除隐藏状态栏、导航栏,全屏的标志
274 | *
275 | * @param activity
276 | */
277 | public void setClearFullScreen(Activity activity) {
278 | mapFullScreen.put(getKey(activity), false);
279 | View decorView = activity.getWindow().getDecorView();
280 | int ui = decorView.getSystemUiVisibility();
281 | ui &= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
282 | & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
283 | & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
284 | & View.SYSTEM_UI_FLAG_FULLSCREEN
285 | & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
286 | decorView.setSystemUiVisibility(ui);
287 | }
288 |
289 | }
290 |
--------------------------------------------------------------------------------
/translucentparent/src/test/java/com/cy/translucentparent/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.cy.translucentparent;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------