├── .gitignore
├── .idea
├── caches
│ └── build_file_checksums.ser
├── codeStyles
│ └── Project.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── siberiadante
│ │ └── titlelayout
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── siberiadante
│ │ │ └── titlelayout
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── drawable-xhdpi
│ │ ├── back_gray.png
│ │ ├── icon_back_black.png
│ │ └── icon_collection.png
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── siberiadante
│ └── titlelayout
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── images
└── show_title.png
├── settings.gradle
└── titlelayoutlib
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
├── androidTest
└── java
│ └── com
│ └── siberiadante
│ └── titlelayoutlib
│ └── ExampleInstrumentedTest.java
├── main
├── AndroidManifest.xml
├── java
│ └── com
│ │ └── siberiadante
│ │ └── titlelayoutlib
│ │ ├── OnMultiTouchListener.java
│ │ ├── TitleBarLayout.java
│ │ ├── TitleLayoutListener.java
│ │ └── utils
│ │ ├── ScreenUtil.java
│ │ ├── StringUtil.java
│ │ └── TransitionTools.java
└── res
│ ├── drawable
│ ├── icon_back.png
│ └── icon_collection.png
│ ├── layout
│ └── title_bar_layout.xml
│ └── values
│ ├── attrs.xml
│ ├── colors.xml
│ └── strings.xml
└── test
└── java
└── com
└── siberiadante
└── titlelayoutlib
└── 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/SiberiaDante/TitleLayout/aa31ac8736d665afa631aeb8252dc861c1a6ae0c/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.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 | # TitleLayout
2 | 多功能、通用的、可在布局或者使用Java代码实现标题栏;支持沉浸式状态栏,支持左侧返回按钮(不需要手动实现页面返回),左侧支持图片+文字、图片、文字;右侧支持图片、文字等。
3 |
4 | ## 堆码不易,star支持,万分感谢
5 | #### 欢迎关注:
6 | [博客园:http://www.cnblogs.com/shen-hua/](http://www.cnblogs.com/shen-hua/)
7 |
8 | [](https://jitpack.io/#SiberiaDante/TitleLayout)
9 |
10 | ```
11 | compile 'com.github.SiberiaDante:TitleLayout:----'//使用 AndroidUtilLib 库时 不需要再重复依赖此库,参考改文档使用即可
12 | ```
13 |
14 | 
15 |
16 | ## 在布局中使用:
17 | ```
18 |
47 | ```
48 | ## 使用Java代码:
49 | ```
50 | TitleBarLayout titleBarLayout = (TitleBarLayout) findViewById(R.id.title_layout);
51 | titleBarLayout.setTitleClickListener(new View.OnClickListener() {
52 | @Override
53 | public void onClick(View view) {
54 | LogUtil.d("title 被点击了");
55 | }
56 | });
57 | //设置Titlesize
58 | titleBarLayout.setTitleSize(30);
59 | //一键设置标题样式
60 | titleBarLayout.setTitleStyle("我是标题", 18, ContextCompat.getColor(this, R.color.action_sheet_blue));
61 | titleBarLayout.setRightImageClickListener(new View.OnClickListener() {
62 | @Override
63 | public void onClick(View view) {
64 | LogUtil.d("右边图片被点击了");
65 | }
66 | });
67 | ```
68 | ## 重点说明:
69 | * 若左侧文字或者按钮为返回键,只需要布局中使用如下代码即可:
70 | ```
71 | dante:d_is_back_view="true"
72 | ```
73 | 或者Java代码中
74 | ```
75 | titleLayout.setIsLeftBackView(true)
76 | ```
77 | 无须在设置onClickListener,this.finish等;如有特殊需要,可设置属性为false,实现方法:
78 | ```
79 | setLeftClickListener(OnClickListener listener)
80 | ```
81 | * 若项目中使用了沉浸式状态栏,则需要在布局中
82 | ```
83 | dante:d_is_immersive_state_bar="true"
84 | ```
85 | * 设置页面为沉浸式状态栏方法:
86 | ```
87 | ScreenUtil.setStatusTranslucent(this);
88 | ```
89 |
90 | ## 其他属性说明
91 | #### xml中的属性:
92 |
93 |
94 | xml属性
95 | 属性说明
96 |
97 |
98 | d_left_image
99 | 左边图片资源
100 |
101 |
102 | d_left_image_width
103 | 左边图片宽(高为匹配父布局)
104 |
105 |
106 | d_left_image_padding_start
107 | 左边图片左边距(默认10dp)
108 |
109 |
110 | d_left_image_padding_end
111 | 左边图片右边距(默认10dp)
112 |
113 |
114 | d_left_text
115 | 左边文字资源
116 |
117 |
118 | d_left_text_size
119 | 左边文字大小(默认16SP)
120 |
121 |
122 | d_left_text_color
123 | 左边文字颜色(默认黑色)
124 |
125 |
126 | d_left_text_style
127 | 设置文字style(normal|bold|italic)
128 |
129 |
130 | d_left_text_padding_start
131 | 左边文字左边距(默认10dp)
132 |
133 |
134 | d_left_text_padding_end
135 | 左边文字右边距(默认10dp)
136 |
137 |
138 | d_title_text
139 | 中间标题文字资源
140 |
141 |
142 | d_title_size
143 | 中间标题文字大小(默认18SP)
144 |
145 |
146 | d_title_color
147 | 中间标题文字颜色(默认黑色)
148 |
149 |
150 | d_title_style
151 | 设置文字style(normal|bold|italic)
152 |
153 |
154 | d_subtitle_text
155 | 中间副标题文字资源
156 |
157 |
158 | d_subtitle_size
159 | 中间副标题文字大小(默认12SP)
160 |
161 |
162 | d_subtitle_color
163 | 中间副标题文字颜色(默认黑色)
164 |
165 |
166 | d_subtitle_style
167 | 设置文字style(normal|bold|italic)
168 |
169 |
170 | d_right_text
171 | 右边文字资源
172 |
173 |
174 | d_right_text_color
175 | 右边文字颜色
176 |
177 |
178 | d_right_text_size
179 | 右边文字大小(默认16sp)
180 |
181 |
182 | d_right_text_style
183 | 设置文字style(normal|bold|italic)
184 |
185 |
186 | d_right_text_padding_end
187 | 右边文字距离右边距
188 |
189 |
190 | d_right_text_padding_start
191 | 右边文字距离左边距
192 |
193 |
194 | d_right_image
195 | 右边图片资源
196 |
197 |
198 | d_right_image_width
199 | 右边图片宽度,高度为匹配父布局
200 |
201 |
202 | d_right_image_padding_end
203 | 右边图片距离右边距
204 |
205 |
206 | d_right_image_padding_start
207 | 右边图片距离左边距
208 |
209 |
210 | d_line_height
211 | 标题栏底部横线高度(默认1px,建议单位使用px)
212 |
213 |
214 | d_line_background
215 | 标题栏底部横线背景颜色(默认黑色)
216 |
217 |
218 | d_title_layout_height
219 | 标题栏整体高度(默认45dp)
220 |
221 |
222 | d_title_layout_background
223 | 标题栏整体背景颜色
224 |
225 |
226 | d_is_back_view
227 | 左侧文字和图片是否为返回键,若是返回键,则自带返回前一页面功能
228 |
229 |
230 | d_is_immersive_state_bar
231 | 是否是沉浸式状态栏,默认false,(为true时标题栏高度包含状态栏高度)
232 |
233 |
234 |
235 | #### Java 代码中
236 |
237 |
238 |
239 | Java代码方法
240 | Java代码方法说明
241 |
242 |
243 | setTitle(CharSequence title)
244 | 设置标题资源
245 |
246 |
247 | setTitleSize(int titleSize)
248 | 设置标题字体大小
249 |
250 |
251 | setTitleColor(int titleColor)
252 | 设置标题字体颜色
253 |
254 |
255 | setTitleStyle(String title, int titleSize, int titleColor)
256 | 设置标题资源、文字大小、文字颜色
257 |
258 |
259 | setSubTitle(CharSequence title)
260 | 设置副标题资源
261 |
262 |
263 | setSubTitleSize(int titleSize)
264 | 设置副标题字体大小
265 |
266 |
267 | setSubTitleColor(int titleColor)
268 | 设置副标题字体颜色
269 |
270 |
271 | setSubTitleStyle(String title, int titleSize, int titleColor)
272 | 设置副标题资源、文字大小、文字颜色
273 |
274 |
275 | setLeftText(String leftText)
276 | 设置左侧文字
277 |
278 |
279 | setLeftTextSize(int leftTextSize)
280 | 设置左侧文字大小
281 |
282 |
283 | setLeftTextColor(int leftTextColor)
284 | 设置左侧文字颜色
285 |
286 |
287 | setLeftStyle(String leftText, int leftTextSize, int leftTextColor)
288 | 设置左侧文字、文字大小、文字颜色
289 |
290 |
291 | setRightText(String rightText)
292 | 设置右侧文字
293 |
294 |
295 | setRightTextSize(int rightTextSize)
296 | 设置右侧文字大小
297 |
298 |
299 | setRightTextColor(int rightTextColor)
300 | 设置右侧文字颜色
301 |
302 |
303 | setTitleClickListener(OnClickListener listener)
304 | 标题点击监听
305 |
306 |
307 | setTitleClickListener(OnMultiTouchListener listener)
308 | 设置标题单击/双击事件
309 |
310 |
311 | setLeftClickListener(OnClickListener listener)
312 | 左侧文字和按钮点击监听
313 |
314 |
315 | setRightTextClickListener(OnClickListener listener)
316 | 右侧文字点击监听
317 |
318 |
319 | setRightImageClickListener(OnClickListener listener)
320 | 右侧按钮点击监听
321 |
322 |
323 | setIsLeftBackView(boolean isLeftBackView)
324 | 设置左侧文字和按钮是否为返回按钮
325 |
326 |
327 | setIsHaveLine(boolean haveLine)
328 | 设置标题栏底部是否有分割线
329 |
330 |
331 | setLeftBackViewVisible
332 | 设置左侧图标显示隐藏
333 |
334 |
335 | setLeftTextViewVisible
336 | 设置左侧文字显示隐藏
337 |
338 |
339 | setRightTextViewVisible
340 | 设置右侧文字显示隐藏
341 |
342 |
343 | setRightImageViewVisible
344 | 设置右侧图标显示隐藏
345 |
346 |
347 | setTitleVisible
348 | 设置标题显示隐藏
349 |
350 |
351 | setSubTitleVisible
352 | 设置副标题显示隐藏
353 |
354 |
355 | setTitleLayoutBackground
356 | 设置标题栏背景颜色
357 |
358 |
359 |
360 | ## 问题
361 | * 设置字体颜色失真,请使用:ContextCompat.getColor(this,R.color.red)
362 |
363 |
364 | ## 更新优化说明
365 | * v1.1.4
366 | * 增加标题栏双击事件、单击事件回调setTitleClickListener(OnMultiTouchListener listener)
367 | * 修复丢失的右边图片点击事件
368 | * 修复设置左右图片Padding造成的问题
369 | * v1.1.3:(2018-08-01发布)
370 | * 增加动态设置标题栏背景颜色
371 | * 增加设置左右视图是否可以点击
372 | * v1.1.0:
373 | * 增加支持Java代码设置所有控件显示隐藏
374 | * v1.0.9:
375 | * 增加支持动态设置左侧和右侧图标功能
376 | * 增加未初始化时UnsupportedOperationException异常提示
377 | * v1.0.4
378 | * 修复bug
379 | * 支持设置文字style(normal|bold|italic)
380 | * v1.0.2
381 | * 增加支持副标题功能
382 | * 优化标题过长显示问题
383 | * v1.0.1
384 | * 多功能、通用的、可在布局或者使用Java代码实现标题栏;
385 | * 支持沉浸式状态栏;
386 | * 支持左侧返回按钮不需要手动实现页面返回;
387 | * 支持左侧按钮,中间标题,右边按钮点击
388 | * 左侧支持图片+文字、单独图片、单独文字;右侧支持单独图片、单独文字等。
389 | * 多功能、通用的、可在布局或者使用Java代码实现标题栏;
390 | * 支持沉浸式状态栏,支持左侧返回按钮(不需要手动实现页面返回),左侧支持图片+文字、图片、文字;右侧支持图片、文字等。
391 |
392 |
393 | [Android开发必备经典收藏集(整理中)]:http://www.jianshu.com/p/a49081da249a
394 | [Android开发常备工具整理中]:https://github.com/SiberiaDante/SiberiaDanteLib
395 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.compileSdkVersion
5 | defaultConfig {
6 | minSdkVersion rootProject.ext.midSdkVersion
7 | targetSdkVersion rootProject.ext.targetSdkVersion
8 | applicationId "com.siberiadante.titlelayout"
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(include: ['*.jar'], dir: 'libs')
23 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
24 | exclude group: 'com.android.support', module: 'support-annotations'
25 | })
26 | implementation "com.android.support:appcompat-v7:$rootProject.ext.supportLibrary"
27 | implementation "com.android.support.constraint:constraint-layout:$rootProject.ext.constraint_layout"
28 | implementation 'junit:junit:4.12'
29 | implementation project(':titlelayoutlib')
30 | }
31 | repositories {
32 | maven { url 'https://jitpack.io' }
33 | }
34 |
--------------------------------------------------------------------------------
/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 C:\Users\shuinsen05\AppData\Local\Android\Sdk/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/siberiadante/titlelayout/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.titlelayout;
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.siberiadante.titlelayout", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/siberiadante/titlelayout/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.titlelayout;
2 |
3 | import android.support.v4.content.ContextCompat;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.widget.Toast;
9 |
10 | import com.siberiadante.titlelayoutlib.OnMultiTouchListener;
11 | import com.siberiadante.titlelayoutlib.TitleBarLayout;
12 | import com.siberiadante.titlelayoutlib.TitleLayoutListener;
13 | import com.siberiadante.titlelayoutlib.utils.ScreenUtil;
14 |
15 | public class MainActivity extends AppCompatActivity {
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 | ScreenUtil.setStatusTranslucent(this);
22 | // //设置Titlesize
23 | // titleBarLayout.setTitleSize(30);
24 | // //一键设置标题样式
25 | // titleBarLayout.setTitleStyle("我是标题", 18, ContextCompat.getColor(this, R.color.colorAccent));
26 |
27 | final TitleBarLayout titleBarLayout2 = (TitleBarLayout) findViewById(R.id.title_layout_two);
28 | titleBarLayout2.setTitle("Java代码设置新的标题");
29 |
30 | final TitleBarLayout titleBarLayout = (TitleBarLayout) findViewById(R.id.title_layout_four);
31 | titleBarLayout.setIsLeftBackView(true);
32 | titleBarLayout.setTitleLayoutBackground(ContextCompat.getColor(this, R.color.colorPrimaryDark));
33 | titleBarLayout.setRightImageClickListener(new View.OnClickListener() {
34 | @Override
35 | public void onClick(View view) {
36 | Toast.makeText(MainActivity.this, "右边的图片被点击了", Toast.LENGTH_SHORT).show();
37 | }
38 | });
39 |
40 | // titleBarLayout.setTitleClickListener(new View.OnClickListener() {
41 | // @Override
42 | // public void onClick(View view) {
43 | // Toast.makeText(MainActivity.this, "标题被点击了", Toast.LENGTH_SHORT).show();
44 | // }
45 | // });
46 | titleBarLayout.setTitleClickListener(new OnMultiTouchListener(new TitleLayoutListener() {
47 | @Override
48 | public void onTitleClickListener() {
49 | Toast.makeText(MainActivity.this, "标题被单击了", Toast.LENGTH_SHORT).show();
50 |
51 | }
52 |
53 | @Override
54 | public void onTitleDoubleClickListener() {
55 | Toast.makeText(MainActivity.this, "标题被双击了", Toast.LENGTH_SHORT).show();
56 |
57 | }
58 | }));
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/back_gray.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/TitleLayout/aa31ac8736d665afa631aeb8252dc861c1a6ae0c/app/src/main/res/drawable-xhdpi/back_gray.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_back_black.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/TitleLayout/aa31ac8736d665afa631aeb8252dc861c1a6ae0c/app/src/main/res/drawable-xhdpi/icon_back_black.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/icon_collection.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/TitleLayout/aa31ac8736d665afa631aeb8252dc861c1a6ae0c/app/src/main/res/drawable-xhdpi/icon_collection.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
32 |
33 |
55 |
56 |
72 |
73 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/TitleLayout/aa31ac8736d665afa631aeb8252dc861c1a6ae0c/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/TitleLayout/aa31ac8736d665afa631aeb8252dc861c1a6ae0c/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/TitleLayout/aa31ac8736d665afa631aeb8252dc861c1a6ae0c/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/TitleLayout/aa31ac8736d665afa631aeb8252dc861c1a6ae0c/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/TitleLayout/aa31ac8736d665afa631aeb8252dc861c1a6ae0c/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/TitleLayout/aa31ac8736d665afa631aeb8252dc861c1a6ae0c/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/TitleLayout/aa31ac8736d665afa631aeb8252dc861c1a6ae0c/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/TitleLayout/aa31ac8736d665afa631aeb8252dc861c1a6ae0c/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/TitleLayout/aa31ac8736d665afa631aeb8252dc861c1a6ae0c/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/TitleLayout/aa31ac8736d665afa631aeb8252dc861c1a6ae0c/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | TitleLayout
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/siberiadante/titlelayout/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.titlelayout;
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 | repositories {
5 | jcenter()
6 | mavenCentral()
7 | google()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.1'
11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | jcenter()
20 | google()
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 | ext {
28 | versionCode = 1
29 | versionName = '1.0.0'
30 |
31 | //Sdk and tools
32 | midSdkVersion = 17
33 | targetSdkVersion = 26
34 | compileSdkVersion = 26
35 | buildToolsVersion = '27.0.0'
36 |
37 | supportLibrary = '27.0.2'
38 | constraint_layout = '1.0.2'
39 |
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/TitleLayout/aa31ac8736d665afa631aeb8252dc861c1a6ae0c/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Mar 06 13:15:43 CST 2018
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-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/images/show_title.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/TitleLayout/aa31ac8736d665afa631aeb8252dc861c1a6ae0c/images/show_title.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':titlelayoutlib'
2 |
--------------------------------------------------------------------------------
/titlelayoutlib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/titlelayoutlib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | group='com.github.SiberiaDante'
4 | android {
5 | compileSdkVersion rootProject.ext.compileSdkVersion
6 | defaultConfig {
7 | minSdkVersion rootProject.ext.midSdkVersion
8 | targetSdkVersion rootProject.ext.targetSdkVersion
9 | versionCode 14
10 | versionName "1.1.4"
11 | }
12 | buildTypes {
13 | release {
14 | minifyEnabled false
15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
16 | }
17 | }
18 | lintOptions {
19 | abortOnError false
20 | }
21 | }
22 |
23 | dependencies {
24 | // compileOnly 'com.android.support:appcompat-v7:25.3.1'
25 | implementation "com.android.support:appcompat-v7:$rootProject.ext.supportLibrary"
26 | }
27 |
--------------------------------------------------------------------------------
/titlelayoutlib/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 C:\Users\shuinsen05\AppData\Local\Android\Sdk/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/titlelayoutlib/src/androidTest/java/com/siberiadante/titlelayoutlib/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.titlelayoutlib;
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.siberiadante.titlelayoutlib.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/titlelayoutlib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/titlelayoutlib/src/main/java/com/siberiadante/titlelayoutlib/OnMultiTouchListener.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.titlelayoutlib;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.os.Handler;
5 | import android.view.MotionEvent;
6 | import android.view.View;
7 |
8 | /**
9 | * Created: SiberiaDante
10 | * Email: 2654828081@qq.com
11 | * GitHub: https://github.com/SiberiaDante
12 | * Blog: http://www.cnblogs.com/shen-hua/
13 | * CreateTime: 2018/3/6
14 | * UpDateTime:
15 | * Describe:
16 | */
17 | public class OnMultiTouchListener implements View.OnTouchListener {
18 | private int clickCount = 0;
19 | private TitleLayoutListener titleLayoutListener;
20 | private Handler mHandler;
21 |
22 | public OnMultiTouchListener(TitleLayoutListener titleLayoutListener) {
23 | this.titleLayoutListener = titleLayoutListener;
24 | mHandler = new Handler();
25 | }
26 |
27 | @SuppressLint("ClickableViewAccessibility")
28 | @Override
29 | public boolean onTouch(View v, MotionEvent event) {
30 | if (event.getAction() == MotionEvent.ACTION_DOWN) {
31 | clickCount++;
32 | mHandler.postDelayed(new Runnable() {
33 | @Override
34 | public void run() {
35 | if (clickCount == 1) {
36 | titleLayoutListener.onTitleClickListener();
37 | } else if (clickCount == 2) {
38 | titleLayoutListener.onTitleDoubleClickListener();
39 | }
40 | mHandler.removeCallbacksAndMessages(null);
41 | clickCount = 0;
42 |
43 | }
44 | }, 500);
45 | }
46 | return false;
47 | }
48 | }
--------------------------------------------------------------------------------
/titlelayoutlib/src/main/java/com/siberiadante/titlelayoutlib/TitleBarLayout.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.titlelayoutlib;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Activity;
5 | import android.content.Context;
6 | import android.content.res.TypedArray;
7 | import android.graphics.Color;
8 | import android.graphics.Typeface;
9 | import android.support.annotation.AttrRes;
10 | import android.support.annotation.IdRes;
11 | import android.support.annotation.NonNull;
12 | import android.support.annotation.Nullable;
13 | import android.util.AttributeSet;
14 | import android.util.Log;
15 | import android.view.GestureDetector;
16 | import android.view.Gravity;
17 | import android.view.LayoutInflater;
18 | import android.view.MotionEvent;
19 | import android.view.View;
20 | import android.view.ViewGroup;
21 | import android.widget.ImageView;
22 | import android.widget.LinearLayout;
23 | import android.widget.RelativeLayout;
24 | import android.widget.TextView;
25 |
26 | import com.siberiadante.titlelayoutlib.utils.ScreenUtil;
27 | import com.siberiadante.titlelayoutlib.utils.StringUtil;
28 | import com.siberiadante.titlelayoutlib.utils.TransitionTools;
29 |
30 | import java.util.Timer;
31 | import java.util.TimerTask;
32 |
33 |
34 | /**
35 | * @Created SiberiaDante
36 | * @Describe: 使用说明GitHub
37 | * 多功能、通用的、可在布局或者使用Java代码实现标题栏;
38 | * 支持沉浸式状态栏;
39 | * 支持左侧返回按钮不需要手动实现页面返回;
40 | * 支持左侧按钮,中间标题,右边按钮点击
41 | * 左侧支持图片+文字、单独图片、单独文字;右侧支持单独图片、单独文字等。
42 | * Time: 2017/9/12
43 | * UpDate:
44 | * Email: 994537867@qq.com
45 | * GitHub: https://github.com/SiberiaDante
46 | */
47 |
48 | public class TitleBarLayout extends RelativeLayout {
49 | public static final String TAG = TitleLayoutListener.class.getSimpleName();
50 | private int mLayoutBarHeight;
51 |
52 | private int mLeftImage;
53 | private int mLeftImageWidth;
54 | private int mLeftImagePaddingStart;
55 | private int mLeftImagePaddingEnd;
56 |
57 | private String mLeftText = "";
58 | private int mLeftTextSize;
59 | private int mLeftTextColor = Color.BLACK;
60 | private int mLeftTextPaddingStart;
61 | private int mLeftTextPaddingEnd;
62 | private int mLeftTextStyle = Typeface.NORMAL;
63 |
64 | private String mTitle = "";
65 | private float mTitleSize;
66 | private int mTitleColor = Color.BLACK;
67 | private int mTitleStyle = Typeface.NORMAL;
68 |
69 | private String mSubTitle = "";
70 | private float mSubTitleSize;
71 | private int mSubTitleColor = Color.GRAY;
72 | private int mSubTitleStyle = Typeface.NORMAL;
73 |
74 | private int mRightImage;
75 | private int mRightImageWidth;
76 | private int mRightImagePaddingEnd;
77 | private int mRightImagePaddingStart;
78 |
79 | private String mRightText = "";
80 | private float mRightTextSize;
81 | private int mRightTextColor = Color.BLACK;
82 | private int mRightTextPaddingEnd;
83 | private int mRightTextPaddingStart;
84 | private int mRightTextStyle = Typeface.NORMAL;
85 |
86 | private int mLineHeight = 1;
87 |
88 | private boolean mIsBackView = true;
89 | private boolean mIsHaveLine = true;
90 | private boolean mIsImmersiveStateBar = false;
91 |
92 | private int mLineBackground = Color.BLACK;
93 | private int mLayoutBackground = Color.BLACK;
94 |
95 | private ImageView mIvLeft;
96 | private TextView mTvLeft;
97 | private TextView mTvTitle;
98 | private TextView mTvSubTitle;
99 | private ImageView mIvRight;
100 | private TextView mTvRight;
101 | private View mViewLine;
102 | private RelativeLayout mRlLayout, mRlLeft, mRlRight;
103 | private LinearLayout mLLCenter;
104 |
105 | private int mStatusBarHeight = 20;
106 |
107 | private Context mContext;
108 |
109 | public TitleBarLayout(@NonNull Context context) {
110 | this(context, null);
111 | }
112 |
113 | public TitleBarLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
114 | this(context, attrs, 0);
115 | }
116 |
117 | public TitleBarLayout(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
118 | super(context, attrs, defStyleAttr);
119 | mLayoutBarHeight = TransitionTools.dip2px(context, 45);
120 | mLeftImageWidth = TransitionTools.dip2px(context, 30);
121 | mLeftImagePaddingStart = TransitionTools.dip2px(context, 10);
122 | mLeftImagePaddingEnd = TransitionTools.dip2px(context, 10);
123 | mLeftTextSize = TransitionTools.dip2px(context, 16);
124 | mLeftTextPaddingStart = TransitionTools.dip2px(context, 10);
125 | mLeftTextPaddingEnd = TransitionTools.dip2px(context, 10);
126 | mTitleSize = TransitionTools.dip2px(context, 18);
127 | mSubTitleSize = TransitionTools.dip2px(context, 12);
128 | mRightImageWidth = TransitionTools.dip2px(context, 30);
129 | mRightImagePaddingEnd = TransitionTools.dip2px(context, 10);
130 | mRightImagePaddingStart = TransitionTools.dip2px(context, 10);
131 | mRightTextSize = TransitionTools.dip2px(context, 16);
132 | mRightTextPaddingEnd = TransitionTools.dip2px(context, 10);
133 | mRightTextPaddingStart = TransitionTools.dip2px(context, 10);
134 |
135 | mContext = context;
136 | mStatusBarHeight = ScreenUtil.getStatusBarHeight();
137 | View inflate = LayoutInflater.from(context).inflate(R.layout.title_bar_layout, null);
138 | addView(inflate);
139 |
140 | TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.TitleBarLayout);
141 |
142 | mLayoutBarHeight = attributes.getDimensionPixelSize(R.styleable.TitleBarLayout_d_title_layout_height, mLayoutBarHeight);
143 | mLayoutBackground = attributes.getColor(R.styleable.TitleBarLayout_d_title_layout_background, mLayoutBackground);
144 |
145 | /*
146 | 左侧图片、图片大小、图片左边距
147 | */
148 | mLeftImage = attributes.getResourceId(R.styleable.TitleBarLayout_d_left_image, 0);
149 | mLeftImageWidth = attributes.getDimensionPixelSize(R.styleable.TitleBarLayout_d_left_image_width, mLeftImageWidth);
150 | mLeftImagePaddingStart = attributes.getDimensionPixelSize(R.styleable.TitleBarLayout_d_left_image_padding_start, mLeftImagePaddingStart);
151 | mLeftImagePaddingEnd = attributes.getDimensionPixelSize(R.styleable.TitleBarLayout_d_left_image_padding_end, mLeftImagePaddingEnd);
152 |
153 | /*
154 | 左侧文字、字体大小、字体颜色、字体左边距
155 | */
156 | mLeftText = attributes.getString(R.styleable.TitleBarLayout_d_left_text);
157 | mLeftTextSize = attributes.getDimensionPixelSize(R.styleable.TitleBarLayout_d_left_text_size, mLeftTextSize);
158 | mLeftTextPaddingStart = attributes.getDimensionPixelSize(R.styleable.TitleBarLayout_d_left_text_padding_start, mLeftTextPaddingStart);
159 | mLeftTextPaddingEnd = attributes.getDimensionPixelSize(R.styleable.TitleBarLayout_d_left_text_padding_end, mLeftTextPaddingEnd);
160 | mLeftTextColor = attributes.getColor(R.styleable.TitleBarLayout_d_left_text_color, mLeftTextColor);
161 | mLeftTextStyle = attributes.getInt(R.styleable.TitleBarLayout_d_left_text_style, mLeftTextStyle);
162 |
163 | /*
164 | 标题文字、字体大小、字体颜色
165 | */
166 | mTitle = attributes.getString(R.styleable.TitleBarLayout_d_title_text);
167 | mTitleSize = attributes.getDimension(R.styleable.TitleBarLayout_d_title_size, mTitleSize);
168 | mTitleColor = attributes.getColor(R.styleable.TitleBarLayout_d_title_color, mTitleColor);
169 | mTitleStyle = attributes.getInt(R.styleable.TitleBarLayout_d_title_style, mTitleStyle);
170 |
171 | /*
172 | 副标题
173 | */
174 | mSubTitle = attributes.getString(R.styleable.TitleBarLayout_d_subtitle_text);
175 | mSubTitleSize = attributes.getDimension(R.styleable.TitleBarLayout_d_subtitle_size, mSubTitleSize);
176 | mSubTitleColor = attributes.getColor(R.styleable.TitleBarLayout_d_subtitle_color, mSubTitleColor);
177 | mSubTitleStyle = attributes.getInt(R.styleable.TitleBarLayout_d_subtitle_style, mSubTitleStyle);
178 |
179 | /*
180 | 右侧图片、图片大小、图片左边距
181 | */
182 | mRightImage = attributes.getResourceId(R.styleable.TitleBarLayout_d_right_image, 0);
183 | mRightImageWidth = attributes.getDimensionPixelSize(R.styleable.TitleBarLayout_d_right_image_width, mRightImageWidth);
184 | mRightImagePaddingEnd = attributes.getDimensionPixelSize(R.styleable.TitleBarLayout_d_right_image_padding_end, mRightImagePaddingEnd);
185 | mRightImagePaddingStart = attributes.getDimensionPixelSize(R.styleable.TitleBarLayout_d_right_image_padding_start, mRightImagePaddingStart);
186 | /*
187 | 右侧文字、字体大小、字体颜色、字体左边距
188 | */
189 | mRightText = attributes.getString(R.styleable.TitleBarLayout_d_right_text);
190 | mRightTextSize = attributes.getDimension(R.styleable.TitleBarLayout_d_right_text_size, mRightTextSize);
191 | mRightTextPaddingEnd = attributes.getDimensionPixelSize(R.styleable.TitleBarLayout_d_right_text_padding_end, mRightTextPaddingEnd);
192 | mRightTextPaddingStart = attributes.getDimensionPixelSize(R.styleable.TitleBarLayout_d_right_text_padding_start, mRightTextPaddingStart);
193 | mRightTextColor = attributes.getColor(R.styleable.TitleBarLayout_d_right_text_color, mRightTextColor);
194 | mRightTextStyle = attributes.getInt(R.styleable.TitleBarLayout_d_right_text_style, mRightTextStyle);
195 |
196 | /*
197 | 底部横线背景、高度
198 | */
199 | mLineBackground = attributes.getColor(R.styleable.TitleBarLayout_d_line_background, mLineBackground);
200 | mLineHeight = attributes.getDimensionPixelSize(R.styleable.TitleBarLayout_d_line_height, mLineHeight);
201 | mIsHaveLine = attributes.getBoolean(R.styleable.TitleBarLayout_d_have_line, mIsHaveLine);
202 |
203 | /*
204 | 左侧图标和文字是否为返回键
205 | */
206 | mIsBackView = attributes.getBoolean(R.styleable.TitleBarLayout_d_is_back_view, mIsBackView);
207 | /*
208 | 是否沉浸式状态栏
209 | */
210 | mIsImmersiveStateBar = attributes.getBoolean(R.styleable.TitleBarLayout_d_is_immersive_state_bar, mIsImmersiveStateBar);
211 |
212 | attributes.recycle();
213 | initView(inflate);
214 | initData();
215 |
216 | }
217 |
218 | private void initView(View inflate) {
219 | mRlLayout = ((RelativeLayout) inflate.findViewById(R.id.sd_rl_title_bar_height));
220 | mRlLeft = ((RelativeLayout) inflate.findViewById(R.id.sd_rl_left));
221 | mRlRight = ((RelativeLayout) inflate.findViewById(R.id.sd_rl_right));
222 | mLLCenter = ((LinearLayout) inflate.findViewById(R.id.sd_ll_center));
223 | mIvLeft = ((ImageView) inflate.findViewById(R.id.sd_iv_left));
224 | mTvLeft = ((TextView) inflate.findViewById(R.id.sd_tv_left));
225 | mTvTitle = ((TextView) inflate.findViewById(R.id.sd_tv_title));
226 | mTvSubTitle = ((TextView) inflate.findViewById(R.id.sd_tv_sub_title));
227 | mIvRight = ((ImageView) inflate.findViewById(R.id.sd_iv_right));
228 | mTvRight = ((TextView) inflate.findViewById(R.id.sd_tv_right));
229 | mViewLine = inflate.findViewById(R.id.sd_view_line);
230 | }
231 |
232 | private void initData() {
233 | initLayoutHeight();
234 | mRlLayout.setBackgroundColor(mLayoutBackground);
235 | //左边图标
236 | settingLeftImage();
237 |
238 | //左边文字
239 | settingLeftText();
240 |
241 | //标题
242 | settingTitle();
243 | //副标题
244 | settingSubTitle();
245 |
246 | //右边图标
247 | settingRightImage();
248 |
249 | //右边文字
250 | settingRightText();
251 |
252 | /**
253 | * 如果是返回键,则点击实现页面返回,否则获取点击事件{@code setLeftClickListener()}
254 | */
255 | settingBackView();
256 |
257 | //横线
258 | settingLine();
259 | }
260 |
261 | private void initLayoutHeight() {
262 | if (mIsImmersiveStateBar) {
263 | int layoutHeight = mLayoutBarHeight + mStatusBarHeight;
264 | LayoutParams mRlLayoutLayoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, layoutHeight);
265 | mRlLayoutLayoutParams.addRule(CENTER_IN_PARENT);
266 | mRlLayout.setLayoutParams(mRlLayoutLayoutParams);
267 | mRlLayout.setPadding(0, mStatusBarHeight, 0, 0);
268 | } else {
269 | LayoutParams mRlLayoutLayoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mLayoutBarHeight);
270 | mRlLayoutLayoutParams.addRule(CENTER_IN_PARENT);
271 | mRlLayout.setLayoutParams(mRlLayoutLayoutParams);
272 | }
273 | }
274 |
275 | private void settingLeftImage() {
276 | if (mLeftImage != 0) {
277 | mIvLeft.setVisibility(VISIBLE);
278 | mIvLeft.setImageResource(mLeftImage);
279 | //image size
280 | ViewGroup.LayoutParams mIvLeftLayoutParams = mIvLeft.getLayoutParams();
281 | mIvLeftLayoutParams.width = mLeftImageWidth + mLeftImagePaddingStart + mLeftImagePaddingEnd;
282 | mIvLeft.setPadding(mLeftImagePaddingStart, 0, mLeftImagePaddingEnd, 0);
283 | mIvLeft.setLayoutParams(mIvLeftLayoutParams);
284 | // mLeftTotalWidth += mLeftImageWidth + mLeftImagePaddingStart + mLeftImagePaddingEnd;
285 |
286 | } else {
287 | mIvLeft.setVisibility(GONE);
288 | }
289 |
290 | }
291 |
292 | private void settingLeftText() {
293 | if (StringUtil.isEmpty(mLeftText)) {
294 | mTvLeft.setPadding(0, 0, 100, 0);
295 | mTvLeft.setVisibility(GONE);
296 | } else {
297 | mTvLeft.setVisibility(VISIBLE);
298 | mTvLeft.setText(mLeftText);
299 | mTvLeft.setTextSize(TransitionTools.px2sp(mContext, mLeftTextSize));
300 | mTvLeft.setTextColor(mLeftTextColor);
301 | mTvLeft.setTypeface(Typeface.defaultFromStyle(mLeftTextStyle));
302 | mTvLeft.setPadding(mLeftTextPaddingStart, 0, mLeftTextPaddingEnd, 0);
303 | // mLeftTotalWidth += mLeftTextPaddingStart;
304 | }
305 | }
306 |
307 | private void settingTitle() {
308 | if (StringUtil.isEmpty(mTitle)) {
309 | mTvTitle.setVisibility(INVISIBLE);
310 | } else {
311 | mTvTitle.setVisibility(VISIBLE);
312 | mTvTitle.setText(mTitle);
313 | mTvTitle.setTypeface(Typeface.defaultFromStyle(mTitleStyle));
314 | mTvTitle.setTextSize(TransitionTools.px2sp(mContext, mTitleSize));
315 | mTvTitle.setTextColor(mTitleColor);
316 | }
317 | }
318 |
319 | private void settingSubTitle() {
320 | if (StringUtil.isEmpty(mSubTitle)) {
321 | mTvSubTitle.setVisibility(GONE);
322 | } else {
323 | mTvSubTitle.setVisibility(VISIBLE);
324 | mTvSubTitle.setText(mSubTitle);
325 | mTvSubTitle.setTextSize(TransitionTools.px2sp(mContext, mSubTitleSize));
326 | mTvSubTitle.setTextColor(mSubTitleColor);
327 | mTvSubTitle.setTypeface(Typeface.defaultFromStyle(mSubTitleStyle));
328 | mTvSubTitle.setGravity(Gravity.TOP | Gravity.CENTER);
329 | mTvTitle.setGravity(Gravity.BOTTOM | Gravity.CENTER);
330 | }
331 | }
332 |
333 | private void settingRightImage() {
334 | if (mRightImage != 0) {
335 | mIvRight.setVisibility(VISIBLE);
336 | mTvRight.setVisibility(GONE);
337 | mIvRight.setImageResource(mRightImage);
338 | ViewGroup.LayoutParams mIvRightLayoutParams = mIvRight.getLayoutParams();
339 | mIvRightLayoutParams.width = mRightImageWidth + mRightImagePaddingEnd + mRightImagePaddingStart;
340 | mIvRight.setLayoutParams(mIvRightLayoutParams);
341 | mIvRight.setPadding(mRightImagePaddingStart, 0, mRightImagePaddingEnd, 0);
342 | } else {
343 | mIvRight.setVisibility(GONE);
344 | }
345 | }
346 |
347 | private void settingRightText() {
348 | if (StringUtil.isEmpty(mRightText)) {
349 | mTvRight.setVisibility(GONE);
350 | } else {
351 | mTvRight.setVisibility(VISIBLE);
352 | mIvRight.setVisibility(GONE);
353 | mTvRight.setText(mRightText);
354 | mTvRight.setTextSize(TransitionTools.px2sp(mContext, mRightTextSize));
355 | mTvRight.setTextColor(mRightTextColor);
356 | mTvRight.setPadding(mRightTextPaddingStart, 0, mRightTextPaddingEnd, 0);
357 | mTvRight.setTypeface(Typeface.defaultFromStyle(mRightTextStyle));
358 | }
359 | }
360 |
361 | private void settingBackView() {
362 | if (mIsBackView) {
363 | mIvLeft.setOnClickListener(new OnClickListener() {
364 | @Override
365 | public void onClick(View view) {
366 | ((Activity) mContext).finish();
367 | }
368 | });
369 | mTvLeft.setOnClickListener(new OnClickListener() {
370 | @Override
371 | public void onClick(View view) {
372 | ((Activity) mContext).finish();
373 | }
374 | });
375 | }
376 |
377 | }
378 |
379 | private void settingLine() {
380 | if (!mIsHaveLine) {
381 | mViewLine.setVisibility(GONE);
382 | return;
383 | }
384 | mViewLine.setBackgroundColor(mLineBackground);
385 | //横线高度
386 | if (mLineHeight != 0) {
387 | ViewGroup.LayoutParams mViewLineLayoutParams = mViewLine.getLayoutParams();
388 | mViewLineLayoutParams.height = mLineHeight;
389 | mViewLine.setLayoutParams(mViewLineLayoutParams);
390 | }
391 | }
392 |
393 | public void setTitleLayoutBackground(int colorRes) {
394 | mRlLayout.setBackgroundColor(colorRes);
395 | }
396 |
397 | /**
398 | * 设置title
399 | */
400 | public void setTitle(String title) {
401 | if (!StringUtil.isEmpty(title)) {
402 | this.mTitle = title;
403 | settingTitle();
404 | }
405 | }
406 |
407 | /**
408 | * 设置标题大小
409 | */
410 | public void setTitleSize(int titleSize) {
411 | if (titleSize != 0) {
412 | mTvTitle.setTextSize(titleSize);
413 | }
414 | }
415 |
416 | /**
417 | * 设置标题颜色
418 | */
419 | public void setTitleColor(int titleColor) {
420 | if (titleColor != 0) {
421 | mTvTitle.setTextColor(titleColor);
422 | }
423 | }
424 |
425 | /**
426 | * 一键设置标题样式、资源等
427 | */
428 | public void setTitleStyle(String title, int titleSize, int titleColor) {
429 | this.mTitle = title;
430 | this.mTitleSize = TransitionTools.dip2px(mContext, titleSize);
431 | this.mTitleColor = titleColor;
432 | settingTitle();
433 | }
434 |
435 | /**
436 | * 设置副title
437 | */
438 | public void setSubTitle(String subTitle) {
439 | if (!StringUtil.isEmpty(subTitle)) {
440 | this.mSubTitle = subTitle;
441 | settingSubTitle();
442 | }
443 | }
444 |
445 | /**
446 | * 设置副标题大小
447 | */
448 | public void setSubTitleSize(int subTitleSize) {
449 | if (subTitleSize != 0) {
450 | mTvSubTitle.setVisibility(VISIBLE);
451 | mTvSubTitle.setTextSize(subTitleSize);
452 | mTvSubTitle.setGravity(Gravity.TOP | Gravity.CENTER);
453 | mTvTitle.setGravity(Gravity.BOTTOM | Gravity.CENTER);
454 | }
455 | }
456 |
457 | /**
458 | * 设置副标题颜色
459 | */
460 | public void setSubTitleColor(int subTitleColor) {
461 | if (subTitleColor != 0) {
462 | mTvSubTitle.setVisibility(VISIBLE);
463 | mTvSubTitle.setTextColor(subTitleColor);
464 | mTvSubTitle.setGravity(Gravity.TOP | Gravity.CENTER);
465 | mTvTitle.setGravity(Gravity.BOTTOM | Gravity.CENTER);
466 | }
467 | }
468 |
469 | /**
470 | * 一键设置副标题样式、资源等
471 | */
472 | public void setSubTitleStyle(String subTitle, int subTitleSize, int subTitleColor) {
473 | this.mSubTitle = subTitle;
474 | this.mSubTitleSize = TransitionTools.dip2px(mContext, subTitleSize);
475 | this.mSubTitleColor = subTitleColor;
476 |
477 | if (!StringUtil.isEmpty(subTitle) && subTitleSize != 0 && subTitleColor != 0) {
478 | settingSubTitle();
479 | }
480 | }
481 |
482 | /**
483 | * 设置左边文字内容
484 | */
485 | public void setLeftText(String leftText) {
486 | if (!StringUtil.isEmpty(leftText)) {
487 | this.mLeftText = leftText;
488 | settingLeftText();
489 | }
490 | }
491 |
492 | /**
493 | * 设置左边文字大小
494 | */
495 | public void setLeftTextSize(int leftTextSize) {
496 | if (leftTextSize != 0) {
497 | mTvLeft.setTextSize(leftTextSize);
498 | }
499 | }
500 |
501 | /**
502 | * 设置左边文字颜色
503 | */
504 | public void setLeftTextColor(int leftTextColor) {
505 | if (leftTextColor != 0) {
506 | mTvLeft.setTextColor(leftTextColor);
507 | }
508 | }
509 |
510 | /**
511 | * 一键设置左侧文字样式、资源等
512 | */
513 | public void setLeftStyle(String leftText, int leftTextSize, int leftTextColor) {
514 |
515 | if (!StringUtil.isEmpty(leftText) && leftTextSize != 0 && leftTextColor != 0) {
516 | this.mLeftText = leftText;
517 | this.mLeftTextSize = TransitionTools.dip2px(mContext, leftTextSize);
518 | this.mLeftTextColor = leftTextColor;
519 | settingLeftText();
520 | }
521 | }
522 |
523 | /**
524 | * 设置右侧文字
525 | */
526 | public void setRightText(String rightText) {
527 | if (!StringUtil.isEmpty(rightText)) {
528 | this.mRightText = rightText;
529 | settingRightText();
530 | }
531 | }
532 |
533 | /**
534 | * 设置右侧文字大小
535 | */
536 | public void setRightTextSize(int rightTextSize) {
537 | if (rightTextSize != 0) {
538 | mTvRight.setTextSize(rightTextSize);
539 | }
540 | }
541 |
542 | /**
543 | * 设置右侧文字颜色
544 | */
545 | public void setRightTextColor(int rightTextColor) {
546 | if (rightTextColor != 0) {
547 | mTvRight.setTextColor(rightTextColor);
548 | }
549 | }
550 |
551 | /**
552 | * 设置右侧文字颜色
553 | */
554 | public void setRightText(String rightText, int rightTextColor) {
555 | if (!StringUtil.isEmpty(rightText) && rightTextColor != 0) {
556 | this.mRightText = rightText;
557 | this.mRightTextColor = rightTextColor;
558 | settingRightText();
559 | }
560 | }
561 |
562 | /**
563 | * 设置右侧文字
564 | */
565 | public void setRightTextStyle(String rightText, int rightTextSize, int rightTextColor) {
566 |
567 | if (!StringUtil.isEmpty(rightText) && rightTextSize != 0 && rightTextColor != 0) {
568 | this.mRightText = rightText;
569 | this.mRightTextSize = TransitionTools.dip2px(mContext, rightTextSize);
570 | this.mRightTextColor = rightTextColor;
571 | settingRightText();
572 | }
573 | }
574 |
575 | /**
576 | * 设置左边图片资源
577 | */
578 | public void setLeftImage(int leftImageResId) {
579 | this.mLeftImage = leftImageResId;
580 | settingLeftImage();
581 | }
582 |
583 | /**
584 | * 设置右边图片资源
585 | */
586 | public void setRightImage(int rightImageResId) {
587 | this.mRightImage = rightImageResId;
588 | settingRightImage();
589 | }
590 |
591 | /**
592 | * 1.0.1之后增加动态设置是否为沉浸式状态栏
593 | */
594 | public void setIsImmersiveStateBar(boolean isImmersiveStateBar) {
595 | mIsImmersiveStateBar = isImmersiveStateBar;
596 | initLayoutHeight();
597 | }
598 |
599 | /**
600 | * 设置是否底部有横线
601 | *
602 | * @param haveLine
603 | */
604 | public void setIsHaveLine(boolean haveLine) {
605 | this.mIsHaveLine = haveLine;
606 | settingLine();
607 | }
608 |
609 | /**
610 | * 标题点击事件
611 | */
612 | @Deprecated
613 | public void setTitleClickListener(OnClickListener listener) {
614 | mTvTitle.setOnClickListener(listener);
615 | }
616 |
617 | /**
618 | * 标题增加单击双击事件
619 | *
620 | * @param onMultiTouchListener
621 | */
622 | @SuppressLint("ClickableViewAccessibility")
623 | public void setTitleClickListener(OnMultiTouchListener onMultiTouchListener) {
624 | mTvTitle.setOnTouchListener(onMultiTouchListener);
625 | }
626 |
627 | /**
628 | * 副标题点击事件
629 | */
630 | public void setSubTitleClickListener(OnClickListener listener) {
631 | mTvSubTitle.setOnClickListener(listener);
632 | }
633 |
634 | /**
635 | * 左边按钮点击事件
636 | */
637 | public void setLeftClickListener(OnClickListener listener) {
638 | mIvLeft.setOnClickListener(listener);
639 | mTvLeft.setOnClickListener(listener);
640 | }
641 |
642 | /**
643 | * 右边文字按钮点击事件
644 | */
645 | public void setRightTextClickListener(OnClickListener listener) {
646 | mTvRight.setOnClickListener(listener);
647 | }
648 |
649 | /**
650 | * 右边图片按钮点击事件
651 | */
652 | public void setRightImageClickListener(OnClickListener listener) {
653 | mIvRight.setOnClickListener(listener);
654 | }
655 |
656 | /**
657 | * 设置左侧文字和按钮是否为返回按钮
658 | */
659 | public void setIsLeftBackView(boolean isLeftBackView) {
660 | mIsBackView = isLeftBackView;
661 | if (!mIsBackView) {
662 | return;
663 | }
664 | if (mLeftImage != 0) {
665 | mIvLeft.setOnClickListener(new OnClickListener() {
666 | @Override
667 | public void onClick(View view) {
668 | ((Activity) mContext).finish();
669 | }
670 | });
671 | }
672 | if (StringUtil.isEmpty(mLeftText)) {
673 | mTvLeft.setOnClickListener(new OnClickListener() {
674 | @Override
675 | public void onClick(View view) {
676 | ((Activity) mContext).finish();
677 |
678 | }
679 | });
680 | }
681 | }
682 |
683 | @Override
684 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
685 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
686 | int mRlLeftMeasuredWidth = mRlLeft.getMeasuredWidth();
687 | int mRlRightMeasuredWidth = mRlRight.getMeasuredWidth();
688 | if (mRlLeftMeasuredWidth > mRlRightMeasuredWidth) {
689 | mLLCenter.setPadding(mRlLeftMeasuredWidth, 0, mRlLeftMeasuredWidth, 0);
690 | } else {
691 | mLLCenter.setPadding(mRlRightMeasuredWidth, 0, mRlRightMeasuredWidth, 0);
692 | }
693 |
694 | }
695 |
696 | /**
697 | * 左侧返回按钮隐藏
698 | */
699 | public void setLeftBackViewVisible(int visibility) {
700 | mIvLeft.setVisibility(visibility);
701 | }
702 |
703 | /**
704 | * 设置左侧文字显示隐藏
705 | */
706 | public void setLeftTextViewVisible(int visibility) {
707 | mTvLeft.setVisibility(visibility);
708 | }
709 |
710 | /**
711 | * 右侧文字设置显示隐藏
712 | */
713 | public void setRightTextViewVisible(int visible) {
714 | mTvRight.setVisibility(visible);
715 | }
716 |
717 | /**
718 | * 右侧图标设置显示隐藏
719 | */
720 | public void setRightImageViewVisible(int visible) {
721 | mIvRight.setVisibility(visible);
722 | }
723 |
724 | /**
725 | * 设置标题显示隐藏
726 | */
727 | public void setTitleVisible(int visible) {
728 | mTvTitle.setVisibility(visible);
729 | }
730 |
731 | /**
732 | * 设置副标题显示隐藏
733 | */
734 | public void setSubTitleVisible(int visible) {
735 | mTvSubTitle.setVisibility(visible);
736 | }
737 |
738 | /**
739 | * 设置左侧文字是否可以点击
740 | */
741 | public void setLeftTextClickable(boolean isClickable) {
742 | mTvLeft.setClickable(isClickable);
743 | mTvLeft.setFocusable(isClickable);
744 | }
745 |
746 | /**
747 | * 设置左侧图片是否可以点击
748 | */
749 | public void setLeftImageClickable(boolean isClickable) {
750 | mIvLeft.setClickable(isClickable);
751 | mIvLeft.setFocusable(isClickable);
752 | }
753 |
754 | /**
755 | * 设置右侧文字是否可以点击
756 | */
757 | public void setRightTextClickable(boolean isClickable) {
758 | mTvRight.setClickable(isClickable);
759 | mTvRight.setFocusable(isClickable);
760 | }
761 |
762 | /**
763 | * 设置右侧图片是否可以点击
764 | */
765 | public void setRightImageClickable(boolean isClickable) {
766 | mIvRight.setClickable(isClickable);
767 | mIvRight.setFocusable(isClickable);
768 | }
769 |
770 | }
771 |
--------------------------------------------------------------------------------
/titlelayoutlib/src/main/java/com/siberiadante/titlelayoutlib/TitleLayoutListener.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.titlelayoutlib;
2 |
3 | /**
4 | * Created: SiberiaDante
5 | * Email: 2654828081@qq.com
6 | * GitHub: https://github.com/SiberiaDante
7 | * Blog: http://www.cnblogs.com/shen-hua/
8 | * CreateTime: 2018/3/6
9 | * UpDateTime:
10 | * Describe:
11 | */
12 | public interface TitleLayoutListener {
13 |
14 | void onTitleClickListener();
15 | void onTitleDoubleClickListener();
16 | }
17 |
--------------------------------------------------------------------------------
/titlelayoutlib/src/main/java/com/siberiadante/titlelayoutlib/utils/ScreenUtil.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.titlelayoutlib.utils;
2 |
3 | import android.annotation.TargetApi;
4 | import android.app.Activity;
5 | import android.app.KeyguardManager;
6 | import android.content.Context;
7 | import android.content.pm.ActivityInfo;
8 | import android.content.res.Configuration;
9 | import android.content.res.Resources;
10 | import android.graphics.Bitmap;
11 | import android.graphics.Color;
12 | import android.os.Build;
13 | import android.provider.Settings;
14 | import android.util.DisplayMetrics;
15 | import android.view.Surface;
16 | import android.view.View;
17 | import android.view.ViewGroup;
18 | import android.view.Window;
19 | import android.view.WindowManager;
20 |
21 | /**
22 | * Created by SiberiaDante on 2017/5/4.
23 | * 屏幕相关工具类
24 | */
25 |
26 | public class ScreenUtil {
27 |
28 | private static final int INVALID_VAL = -1;
29 | private static final int COLOR_DEFAULT = Color.parseColor("#20000000");
30 | private static final String STATUS_BAR_HEIGHT_RES_NAME = "status_bar_height";
31 |
32 | public static float getDensity(Activity activity) {
33 | //屏幕dpi
34 | DisplayMetrics displayMetrics = new DisplayMetrics();
35 | activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
36 | return displayMetrics.density;
37 | }
38 |
39 | /**
40 | * @return 获取屏幕的宽 单位:px
41 | */
42 | public static int getScreenWidthPx(Context context) {
43 | WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
44 | DisplayMetrics dm = new DisplayMetrics();
45 | windowManager.getDefaultDisplay().getMetrics(dm);
46 | return dm.widthPixels;
47 | }
48 |
49 | /**
50 | * @return 获取屏幕的高 单位:px
51 | */
52 | public static int getScreenHeightPx(Context context) {
53 | WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
54 | DisplayMetrics dm = new DisplayMetrics();
55 | windowManager.getDefaultDisplay().getMetrics(dm);
56 | return dm.heightPixels;
57 |
58 | }
59 |
60 | /**
61 | * 获取屏幕的宽度(单位:px)
62 | *
63 | * @return 屏幕宽
64 | */
65 | public static int getScreenWidth(Context context) {
66 | return context.getResources().getDisplayMetrics().widthPixels;
67 | }
68 |
69 | /**
70 | * 获取屏幕的高度(单位:px)
71 | *
72 | * @return 屏幕高
73 | */
74 | public static int getScreenHeight(Context context) {
75 | return context.getResources().getDisplayMetrics().heightPixels;
76 | }
77 |
78 | /**
79 | * @return 获取屏幕的宽 单位:dp
80 | */
81 | public static int getScreenWidthDp(Context context) {
82 | WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
83 | DisplayMetrics dm = new DisplayMetrics();
84 | windowManager.getDefaultDisplay().getMetrics(dm);
85 | return TransitionTools.px2dip(context, dm.widthPixels);
86 | }
87 |
88 | /**
89 | * @return 获取屏幕的高 单位:dp
90 | */
91 | public static int getScreenHeightDp(Context context) {
92 | WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
93 | DisplayMetrics dm = new DisplayMetrics();
94 | windowManager.getDefaultDisplay().getMetrics(dm);
95 | return TransitionTools.px2dip(context, dm.heightPixels);
96 | }
97 |
98 | /**
99 | * 透明状态栏
100 | * 需要设置的xml中增加属性:
101 | * android:clipToPadding="true"
102 | * android:fitsSystemWindows="true"
103 | *
104 | * @param activity
105 | */
106 | public static void setStatusTranslucent(Activity activity) {
107 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
108 | //透明状态栏
109 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
110 | }
111 | }
112 |
113 | /**
114 | * 透明导航栏
115 | *
116 | * @param activity
117 | */
118 | public static void setNavigationTranslucent(Activity activity) {
119 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
120 | //透明导航栏
121 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
122 | }
123 | }
124 |
125 | /**
126 | * 透明状态栏和透明导航栏
127 | *
128 | * @param activity
129 | */
130 | public static void setTranslucent(Activity activity) {
131 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
132 | //透明状态栏
133 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
134 | //透明导航栏
135 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
136 | }
137 | }
138 |
139 | /**
140 | * 设置全屏
141 | *
142 | * @param activity
143 | */
144 | public static void setFullScreen(Activity activity) {
145 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
146 | Window window = activity.getWindow();
147 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
148 | | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
149 | window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
150 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
151 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
152 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
153 | window.setStatusBarColor(Color.TRANSPARENT);
154 | window.setNavigationBarColor(Color.TRANSPARENT);
155 | }
156 | }
157 |
158 | /**
159 | * 计算状态栏高度
160 | *
161 | * @return 状态栏高度
162 | */
163 | public static int getStatusBarHeight() {
164 | return getInternalDimensionSize(Resources.getSystem(), STATUS_BAR_HEIGHT_RES_NAME);
165 | }
166 |
167 | private static int getInternalDimensionSize(Resources res, String key) {
168 | int result = 0;
169 | int resourceId = res.getIdentifier(key, "dimen", "android");
170 | if (resourceId > 0) {
171 | result = res.getDimensionPixelSize(resourceId);
172 | }
173 | return result;
174 | }
175 |
176 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
177 | public static void compat(Activity activity, int statusColor) {
178 |
179 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
180 | if (statusColor != INVALID_VAL) {
181 | activity.getWindow().setStatusBarColor(statusColor);
182 | }
183 | return;
184 | }
185 |
186 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
187 | int color = COLOR_DEFAULT;
188 | ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
189 | if (statusColor != INVALID_VAL) {
190 | color = statusColor;
191 | }
192 | View statusBarView = contentView.getChildAt(0);
193 | //改变颜色时避免重复添加statusBarView
194 | if (statusBarView != null && statusBarView.getMeasuredHeight() == getStatusBarHeight(activity)) {
195 | statusBarView.setBackgroundColor(color);
196 | return;
197 | }
198 | statusBarView = new View(activity);
199 | ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
200 | getStatusBarHeight(activity));
201 | statusBarView.setBackgroundColor(color);
202 | contentView.addView(statusBarView, lp);
203 | }
204 |
205 | }
206 |
207 | public static void compat(Activity activity) {
208 | compat(activity, INVALID_VAL);
209 | }
210 |
211 |
212 | public static int getStatusBarHeight(Context context) {
213 | int result = 0;
214 | int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
215 | if (resourceId > 0) {
216 | result = context.getResources().getDimensionPixelSize(resourceId);
217 | }
218 | return result;
219 | }
220 |
221 | /**
222 | * 设置屏幕为横屏
223 | * 还有一种就是在Activity中加属性android:screenOrientation="landscape"
224 | * 不设置Activity的android:configChanges时,切屏会重新调用各个生命周期,切横屏时会执行一次,切竖屏时会执行两次
225 | * 设置Activity的android:configChanges="orientation"时,切屏还是会重新调用各个生命周期,切横、竖屏时只会执行一次
226 | * 设置Activity的android:configChanges="orientation|keyboardHidden|screenSize"(4.0以上必须带最后一个参数)时
227 | * 切屏不会重新调用各个生命周期,只会执行onConfigurationChanged方法
228 | *
229 | * @param activity activity
230 | */
231 | public static void setLandscape(Activity activity) {
232 | activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
233 | }
234 |
235 | /**
236 | * 设置屏幕为竖屏
237 | *
238 | * @param activity activity
239 | */
240 | public static void setPortrait(Activity activity) {
241 | activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
242 | }
243 |
244 | /**
245 | * 判断是否横屏
246 | *
247 | * @return {@code true}: 是 {@code false}: 否
248 | */
249 | public static boolean isLandscape(Context context) {
250 | return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
251 | }
252 |
253 | /**
254 | * 判断是否竖屏
255 | *
256 | * @return {@code true}: 是 {@code false}: 否
257 | */
258 | public static boolean isPortrait(Context context) {
259 | return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
260 | }
261 |
262 | /**
263 | * 获取屏幕旋转角度
264 | *
265 | * @param activity activity
266 | * @return 屏幕旋转角度
267 | */
268 | public static int getScreenRotation(Activity activity) {
269 | switch (activity.getWindowManager().getDefaultDisplay().getRotation()) {
270 | default:
271 | case Surface.ROTATION_0:
272 | return 0;
273 | case Surface.ROTATION_90:
274 | return 90;
275 | case Surface.ROTATION_180:
276 | return 180;
277 | case Surface.ROTATION_270:
278 | return 270;
279 | }
280 | }
281 |
282 | /**
283 | * 获取当前屏幕截图,包含状态栏
284 | *
285 | * @param activity activity
286 | * @return Bitmap
287 | */
288 | public static Bitmap captureWithStatusBar(Activity activity) {
289 | View view = activity.getWindow().getDecorView();
290 | view.setDrawingCacheEnabled(true);
291 | view.buildDrawingCache();
292 | Bitmap bmp = view.getDrawingCache();
293 | DisplayMetrics dm = new DisplayMetrics();
294 | activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
295 | Bitmap ret = Bitmap.createBitmap(bmp, 0, 0, dm.widthPixels, dm.heightPixels);
296 | view.destroyDrawingCache();
297 | return ret;
298 | }
299 |
300 | /**
301 | * 获取当前屏幕截图,不包含状态栏
302 | *
303 | * @param activity activity
304 | * @return Bitmap
305 | */
306 | public static Bitmap captureWithoutStatusBar(Activity activity) {
307 | View view = activity.getWindow().getDecorView();
308 | view.setDrawingCacheEnabled(true);
309 | view.buildDrawingCache();
310 | Bitmap bmp = view.getDrawingCache();
311 | int statusBarHeight = getStatusBarHeight(activity);//获取状态栏高度
312 | DisplayMetrics dm = new DisplayMetrics();
313 | activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
314 | Bitmap ret = Bitmap.createBitmap(bmp, 0, statusBarHeight, dm.widthPixels, dm.heightPixels - statusBarHeight);
315 | view.destroyDrawingCache();
316 | return ret;
317 | }
318 |
319 | /**
320 | * 判断是否锁屏
321 | *
322 | * @return {@code true}: 是 {@code false}: 否
323 | */
324 | public static boolean isScreenLock(Context context) {
325 | KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
326 | return km.inKeyguardRestrictedInputMode();
327 | }
328 |
329 | /**
330 | * 设置进入休眠时长
331 | * 需添加权限 {@code }
332 | *
333 | * @param duration 时长
334 | */
335 | public static void setSleepDuration(Context context, int duration) {
336 | Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, duration);
337 | }
338 |
339 | /**
340 | * 获取进入休眠时长
341 | *
342 | * @return 进入休眠时长,报错返回-123
343 | */
344 | public static int getSleepDuration(Context context) {
345 | try {
346 | return Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT);
347 | } catch (Settings.SettingNotFoundException e) {
348 | e.printStackTrace();
349 | return -123;
350 | }
351 | }
352 | }
353 |
--------------------------------------------------------------------------------
/titlelayoutlib/src/main/java/com/siberiadante/titlelayoutlib/utils/StringUtil.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.titlelayoutlib.utils;
2 |
3 | import java.util.regex.Matcher;
4 | import java.util.regex.Pattern;
5 |
6 | /**
7 | * @Created: SiberiaDante
8 | * @Date: 2017/7/10
9 | * @Describe:
10 | * @github: https://github.com/SiberiaDante
11 | * @博客园: http://www.cnblogs.com/shen-hua/
12 | */
13 |
14 | public class StringUtil {
15 | /**
16 | * 判断字符串是否为空
17 | *
18 | * @param str
19 | * @return
20 | */
21 | public static boolean isEmpty(String str) {
22 | return (str == null || str.trim().length() == 0);
23 | }
24 |
25 | /**
26 | * str1 中是否包含str2
27 | *
28 | * @param str1
29 | * @param str2
30 | * @return
31 | */
32 | public static boolean isHaveString(String str1, String str2) {
33 | if (str1.contains(str2)) {
34 | return true;
35 | } else {
36 | return false;
37 | }
38 | }
39 |
40 | /**
41 | * 半角转换为全角
42 | * SBC全角;DBC半角
43 | *
44 | * @param text
45 | * @return
46 | */
47 | public static String toSBC(String text) {
48 | char[] c = text.toCharArray();
49 | for (int i = 0; i < c.length; i++) {
50 | if (c[i] == 12288) {
51 | c[i] = (char) 32;
52 | continue;
53 | }
54 | if (c[i] > 65280 && c[i] < 65375)
55 | c[i] = (char) (c[i] - 65248);
56 | }
57 | return new String(c);
58 | }
59 |
60 | /**
61 | * 去除特殊字符或将所有中文标号替换为英文标号
62 | *
63 | * @param str
64 | * @return
65 | */
66 | public static String removeSpecialString(String str) {
67 | str = str.replaceAll("【", "[").replaceAll("】", "]")
68 | .replaceAll("!", "!").replaceAll(":", ":");// 替换中文标号
69 | String regEx = "[『』]"; // 清除掉特殊字符
70 | Pattern p = Pattern.compile(regEx);
71 | Matcher m = p.matcher(str);
72 | return m.replaceAll("").trim();
73 | }
74 |
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/titlelayoutlib/src/main/java/com/siberiadante/titlelayoutlib/utils/TransitionTools.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.titlelayoutlib.utils;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.util.DisplayMetrics;
6 |
7 | public class TransitionTools {
8 | public static float getDensity(Activity activity) {
9 | //屏幕dpi
10 | DisplayMetrics displayMetrics = new DisplayMetrics();
11 | activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
12 | return displayMetrics.density;
13 | }
14 |
15 | /**
16 | * dip转为 px
17 | */
18 | public static int dip2px(Context context, float dipValue) {
19 | // final float scale = Resources.getSystem().getDisplayMetrics().density;
20 | final float scale = context.getResources().getDisplayMetrics().density;
21 | return (int) (dipValue * scale + 0.5f);
22 | }
23 |
24 | /**
25 | * px 转为 dip
26 | */
27 | public static int px2dip(Context context, float pxValue) {
28 | final float scale = context.getResources().getDisplayMetrics().density;
29 |
30 | return (int) (pxValue / scale + 0.5f);
31 | }
32 |
33 | /**
34 | * 将px值转换为sp值,保证文字大小不变
35 | *
36 | * @param pxValue
37 | * @return
38 | */
39 | public static int px2sp(Context context, float pxValue) {
40 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
41 | return (int) (pxValue / fontScale + 0.5f);
42 | }
43 |
44 | /**
45 | * 将sp值转换为px值,保证文字大小不变
46 | *
47 | * @param spValue
48 | * @return
49 | */
50 | public static int sp2px(Context context, float spValue) {
51 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
52 | return (int) (spValue * fontScale + 0.5f);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/titlelayoutlib/src/main/res/drawable/icon_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/TitleLayout/aa31ac8736d665afa631aeb8252dc861c1a6ae0c/titlelayoutlib/src/main/res/drawable/icon_back.png
--------------------------------------------------------------------------------
/titlelayoutlib/src/main/res/drawable/icon_collection.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SiberiaDante/TitleLayout/aa31ac8736d665afa631aeb8252dc861c1a6ae0c/titlelayoutlib/src/main/res/drawable/icon_collection.png
--------------------------------------------------------------------------------
/titlelayoutlib/src/main/res/layout/title_bar_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
28 |
29 |
38 |
39 |
40 |
44 |
45 |
53 |
54 |
64 |
65 |
66 |
71 |
72 |
81 |
82 |
91 |
92 |
93 |
94 |
95 |
96 |
102 |
103 |
--------------------------------------------------------------------------------
/titlelayoutlib/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
--------------------------------------------------------------------------------
/titlelayoutlib/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #000000
4 | #ffffff
5 | #fa0303
6 | #030bfa
7 |
8 |
--------------------------------------------------------------------------------
/titlelayoutlib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | TitleLayoutLib
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/titlelayoutlib/src/test/java/com/siberiadante/titlelayoutlib/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.siberiadante.titlelayoutlib;
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 | }
--------------------------------------------------------------------------------