├── .gitignore ├── LICENSE.txt ├── README.md ├── apk ├── qr.png └── sample.apk ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── aries │ │ └── title │ │ ├── DrawerHelper.java │ │ ├── MainActivity.java │ │ ├── TitleEditActivity.java │ │ ├── TitleFragment.java │ │ ├── WebViewActivity.java │ │ ├── adapter │ │ ├── DrawerAdapter.java │ │ └── TitleAdapter.java │ │ ├── base │ │ ├── BaseActivity.java │ │ └── BaseRecycleActivity.java │ │ ├── entity │ │ ├── DrawerEntity.java │ │ ├── TitleEntity.java │ │ └── WidgetEntity.java │ │ ├── manager │ │ └── GlideManager.java │ │ └── util │ │ ├── AppUtil.java │ │ └── ViewUtil.java │ └── res │ ├── drawable-xhdpi │ ├── ic_arrow_back_white.png │ ├── ic_arrow_left.png │ ├── ic_arrow_right.png │ ├── ic_close.xml │ ├── ic_menu.png │ ├── ic_menu_white.png │ └── ic_share.xml │ ├── drawable │ ├── fast_shape_placeholder_circle.xml │ ├── fast_shape_placeholder_common.xml │ ├── fast_shape_placeholder_round.xml │ └── ic_launcher.xml │ ├── layout │ ├── activity_main.xml │ ├── activity_title_edit.xml │ ├── activity_web_view.xml │ ├── fragment_title.xml │ ├── item_widget.xml │ ├── layout_drawer.xml │ ├── layout_recycle_view.xml │ ├── layout_title.xml │ ├── layout_title_bar.xml │ └── layout_title_header.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── buildConfig.gradle ├── gradle.properties ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── aries │ │ └── ui │ │ ├── util │ │ ├── KeyboardUtil.java │ │ ├── RomUtil.java │ │ └── StatusBarUtil.java │ │ └── view │ │ └── title │ │ └── TitleBarView.java │ └── res │ └── values │ ├── attrs.xml │ └── strings.xml ├── screenshot ├── 4.1.gif ├── 4.4.gif ├── 5.1.gif ├── 6.0.gif └── 7.0.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | .idea 4 | /local.properties 5 | /.idea/workspace.xml 6 | /.idea/libraries 7 | .DS_Store 8 | /build 9 | /captures 10 | .externalNativeBuild 11 | /.gitignore 12 | /*.gitignore 13 | /.idea 14 | /gradle 15 | /gradlew.bat 16 | /gradlew 17 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 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 | # TitleBarView-一个自带沉浸状态栏效果的Android自定义标题栏控件 2 | ---------- 3 | [![fir.im](https://img.shields.io/badge/download-fir.im-blue.svg)](https://fir.im/pmb2) 4 | [![](https://jitpack.io/v/AriesHoo/TitleBarView.svg)](https://jitpack.io/#AriesHoo/TitleBarView) 5 | [![](https://img.shields.io/github/release/AriesHoo/TitleBarView.svg)](https://github.com/AriesHoo/TitleBarView/releases) 6 | [![API](https://img.shields.io/badge/API-11%2B-green.svg?style=flat)](https://android-arsenal.com/api?level=11) 7 | [![GitHub license](https://img.shields.io/github/license/AriesHoo/TitleBarView.svg)](http://www.apache.org/licenses/LICENSE-2.0.html) 8 | [![](https://img.shields.io/badge/简书-AriesHoo-blue.svg)](http://www.jianshu.com/u/a229eee96115) 9 | [![](https://img.shields.io/badge/简书解析-TitleBarView:一个自带沉浸状态栏效果的Android自定义标题栏控件-blue.svg)](http://www.jianshu.com/p/34ace867b29f) 10 | 11 | 12 | ## 简介: 13 | 14 | 一个支持Android 4.4以上版本沉浸式及半透明状态栏效果的 TitleBarView;更全常见UI库参看 [UIWidget](https://github.com/AriesHoo/UIWidget) 15 | 16 | **说明2.0.0以后版本UIWidget维护,不再做版本更新** 17 | 18 | #### TitleBarView是基于ViewGroup的扩展,主要具有以下特性 19 | 20 | 21 | - 支持Android 4.4以上版本沉浸式(关于这个叫法大家不要去纠结,意会即可)及半透明状态栏效果 22 | 23 | - 实现MIUI V6、Flyme 4.0、Android 6.0以上状态栏文字颜色切换(当然只能黑或白色) 24 | 25 | - 支持设置主/副标题跑马灯效果 26 | 27 | - 支持Java代码及XML设置众多自定义属性 28 | 29 | - 支持Java代码链式调用方便快捷 30 | 31 | - 可设置左边文字/图片、中间主、副标题、右边文字/图片 32 | 33 | - 支持Java代码添加左边、中间、右边 View 34 | 35 | 36 | 说明:此处沉浸式状态栏为状态栏透明化且布局延伸至状态栏下效果,非状态栏着色模式 37 | 38 | 详情实现流程解析请移步:[TitleBarView-一个自带沉浸状态栏效果的Android自定义标题栏控件](http://www.jianshu.com/p/34ace867b29f) 39 | 40 | [[Sample PC Download]](https://github.com/AriesHoo/TitleBarView/blob/master/apk/sample.apk) 41 | 42 | [[Sample Mobile Download]](https://fir.im/pmb2) 43 | 44 | ![](https://github.com/AriesHoo/TitleBarView/blob/master/apk/qr.png) 45 | 46 | 47 | **Gradle集成** 48 | 49 | ``` 50 | allprojects { 51 | repositories { 52 | ... 53 | maven { url "https://jitpack.io" } 54 | } 55 | } 56 | ``` 57 | 58 | ``` 59 | dependencies { 60 | // compile 'com.github.AriesHoo:TitleBarView:2.0.0' 61 | compile 'com.github.AriesHoo:TitleBarView:${LATEST_VERSION}' 62 | } 63 | ``` 64 | 65 | ## 录屏预览 66 | 67 | Android 4.1 68 | 69 | ![](https://github.com/AriesHoo/TitleBarView/blob/master/screenshot/4.1.gif) 70 | 71 | Android 4.4 72 | 73 | ![](https://github.com/AriesHoo/TitleBarView/blob/master/screenshot/4.4.gif) 74 | 75 | Android 5.1 76 | 77 | ![](https://github.com/AriesHoo/TitleBarView/blob/master/screenshot/5.1.gif) 78 | 79 | Android 6.0 80 | 81 | ![](https://github.com/AriesHoo/TitleBarView/blob/master/screenshot/6.0.gif) 82 | 83 | Android 7.0 84 | 85 | ![](https://github.com/AriesHoo/TitleBarView/blob/master/screenshot/7.0.gif) 86 | 87 | 其它UI库查看:[UIWidget](https://github.com/AriesHoo/UIWidget) 88 | 89 | ## 鸣谢 90 | 91 | - [bacy/titlebar](https://github.com/bacy/titlebar) 92 | 93 | - [sandalli/TitleBarLibs](https://github.com/sandalli/TitleBarLibs) 94 | 95 | - [laobie/StatusBarUtil](https://github.com/laobie/StatusBarUtil) 96 | 97 | ## License 98 | 99 | ``` 100 | Copyright 2016 Aries Hoo 101 | 102 | Licensed under the Apache License, Version 2.0 (the "License"); 103 | you may not use this file except in compliance with the License. 104 | You may obtain a copy of the License at 105 | 106 | http://www.apache.org/licenses/LICENSE-2.0 107 | 108 | Unless required by applicable law or agreed to in writing, software 109 | distributed under the License is distributed on an "AS IS" BASIS, 110 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 111 | See the License for the specific language governing permissions and 112 | limitations under the License. 113 | ``` 114 | 115 | -------------------------------------------------------------------------------- /apk/qr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AriesHoo/TitleBarView/70e9729a232c66a00a05456f35839f4b6b90c946/apk/qr.png -------------------------------------------------------------------------------- /apk/sample.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AriesHoo/TitleBarView/70e9729a232c66a00a05456f35839f4b6b90c946/apk/sample.apk -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.neenbedankt.android-apt' 3 | 4 | android { 5 | def ext = rootProject.ext 6 | compileSdkVersion ext.compileSdkVersion 7 | buildToolsVersion ext.buildToolsVersion 8 | defaultConfig { 9 | applicationId "com.aries.titile" 10 | minSdkVersion ext.minSdkVersion 11 | targetSdkVersion ext.targetSdkVersion 12 | versionCode 20 13 | versionName "2.0.0" 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | } 23 | 24 | dependencies { 25 | compile fileTree(dir: 'libs', include: ['*.jar']) 26 | def supportVersion = rootProject.ext.supportVersion 27 | compile 'com.android.support:appcompat-v7:'.concat(supportVersion) 28 | compile 'com.android.support:recyclerview-v7:'.concat(supportVersion) 29 | apt 'com.jakewharton:butterknife-compiler:8.7.0' 30 | compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.8.0' 31 | compile 'com.jakewharton:butterknife:8.7.0' 32 | compile 'com.github.AriesHoo:RadiusView:1.1.0' 33 | compile 'com.just.agentweb:agentweb:2.0.0' 34 | //图片加载 35 | compile 'com.github.bumptech.glide:glide:4.0.0' 36 | annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0' 37 | // compile project(':library') 38 | compile 'com.github.AriesHoo:TitleBarView:2.0.0' 39 | } 40 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\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 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/aries/title/DrawerHelper.java: -------------------------------------------------------------------------------- 1 | package com.aries.title; 2 | 3 | import android.app.Activity; 4 | import android.support.v7.widget.LinearLayoutManager; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.View; 7 | 8 | import com.aries.title.adapter.DrawerAdapter; 9 | import com.aries.title.entity.DrawerEntity; 10 | import com.chad.library.adapter.base.BaseQuickAdapter; 11 | import com.chad.library.adapter.base.listener.OnItemClickListener; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * Created: AriesHoo on 2017/7/17 17:26 17 | * Function: 抽屉栏控制类 18 | * Desc: 19 | */ 20 | public class DrawerHelper { 21 | private static volatile DrawerHelper instance; 22 | 23 | private DrawerHelper() { 24 | } 25 | 26 | public static DrawerHelper getInstance() { 27 | if (instance == null) { 28 | synchronized (DrawerHelper.class) { 29 | if (instance == null) { 30 | instance = new DrawerHelper(); 31 | } 32 | } 33 | } 34 | return instance; 35 | } 36 | 37 | public void initRecyclerView(final Activity mContext, RecyclerView mRecyclerViewDrawer, List list) { 38 | final BaseQuickAdapter mAdapterDrawer = new DrawerAdapter(mContext); 39 | mRecyclerViewDrawer.setLayoutManager(new LinearLayoutManager(mContext)); 40 | mRecyclerViewDrawer.setAdapter(mAdapterDrawer); 41 | mRecyclerViewDrawer.addOnItemTouchListener(new OnItemClickListener() { 42 | @Override 43 | public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) { 44 | DrawerEntity entity = (DrawerEntity) mAdapterDrawer.getItem(position); 45 | WebViewActivity.start(mContext, entity.url); 46 | } 47 | }); 48 | mAdapterDrawer.setNewData(list); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/aries/title/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.aries.title; 2 | 3 | import android.graphics.Color; 4 | import android.os.Build; 5 | import android.os.Bundle; 6 | import android.support.v4.widget.DrawerLayout; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.support.v7.widget.SwitchCompat; 9 | import android.view.View; 10 | import android.widget.CompoundButton; 11 | import android.widget.FrameLayout; 12 | import android.widget.ImageView; 13 | import android.widget.LinearLayout; 14 | import android.widget.ScrollView; 15 | import android.widget.SeekBar; 16 | import android.widget.TextView; 17 | 18 | import com.aries.title.adapter.TitleAdapter; 19 | import com.aries.title.base.BaseRecycleActivity; 20 | import com.aries.title.entity.DrawerEntity; 21 | import com.aries.title.entity.TitleEntity; 22 | import com.aries.title.manager.GlideManager; 23 | import com.aries.title.util.ViewUtil; 24 | import com.aries.ui.util.RomUtil; 25 | import com.aries.ui.util.StatusBarUtil; 26 | import com.aries.ui.view.title.TitleBarView; 27 | import com.chad.library.adapter.base.BaseQuickAdapter; 28 | import com.chad.library.adapter.base.BaseViewHolder; 29 | 30 | import java.util.ArrayList; 31 | import java.util.List; 32 | 33 | import butterknife.BindView; 34 | 35 | /** 36 | * Created: AriesHoo on 2017-02-09 10:24 37 | * Function: 演示TitleBarView常见用法 38 | * Desc: 39 | */ 40 | public class MainActivity extends BaseRecycleActivity { 41 | 42 | @BindView(R.id.drawer_root) DrawerLayout drawerRoot; 43 | @BindView(R.id.sv_slide) ScrollView svSlide; 44 | @BindView(R.id.titleBarDrawer) TitleBarView titleBarDrawer; 45 | @BindView(R.id.fLayout_drawer) FrameLayout fLayoutDrawer; 46 | @BindView(R.id.rv_contentDrawer) RecyclerView mRecyclerViewDrawer; 47 | @BindView(R.id.iv_headDrawer) ImageView ivHead; 48 | private SwitchCompat sBtnImmersible; 49 | private SwitchCompat sBtnLight; 50 | private SwitchCompat sBtnLine; 51 | private LinearLayout lLayoutAlpha; 52 | private SeekBar sBarAlpha; 53 | private TextView tvStatusAlpha; 54 | 55 | private boolean isImmersible = true; 56 | private boolean isLight = true; 57 | private boolean canImmersible = true; 58 | private boolean canLight = true; 59 | 60 | private BaseQuickAdapter mAdapter; 61 | private BaseQuickAdapter mAdapterDrawer; 62 | protected View vHeader; 63 | private int mAlpha = 102; 64 | 65 | @Override 66 | protected boolean setLoadMore() { 67 | return false; 68 | } 69 | 70 | @Override 71 | protected void setTitleBar() { 72 | titleBar.setTitleMainText("主标题") 73 | .setTitleSubText(getSubText()) 74 | .setRightTextDrawable(isWhite ? R.drawable.ic_menu : R.drawable.ic_menu_white) 75 | .setOnRightTextClickListener(new View.OnClickListener() { 76 | @Override 77 | public void onClick(View v) { 78 | drawerRoot.openDrawer(svSlide); 79 | } 80 | }); 81 | 82 | } 83 | 84 | private String getSubText() { 85 | String text = "Android" + Build.VERSION.RELEASE; 86 | if (RomUtil.isMIUI()) { 87 | text += "-MIUI" + RomUtil.getMIUIVersion(); 88 | } else if (RomUtil.isFlyme()) { 89 | text += "-Flyme" + RomUtil.getFlymeVersionCode(); 90 | } else if (RomUtil.isEMUI()) { 91 | text += "-EMUI" + RomUtil.getEMUIVersion(); 92 | } 93 | return text; 94 | } 95 | 96 | @Override 97 | protected int getLayout() { 98 | return R.layout.activity_main; 99 | } 100 | 101 | @Override 102 | protected BaseQuickAdapter getAdapter() { 103 | mAdapter = new TitleAdapter(mContext); 104 | return mAdapter; 105 | } 106 | 107 | @Override 108 | protected void loadData(int page) { 109 | 110 | } 111 | 112 | 113 | @Override 114 | protected void initView(Bundle bundle) { 115 | super.initView(bundle); 116 | GlideManager.loadCircleImg("https://avatars3.githubusercontent.com/u/19605922?v=4&s=460", ivHead); 117 | titleBarDrawer.setImmersible(mContext, isImmersible, isLight); 118 | vHeader = View.inflate(mContext, R.layout.layout_title_header, null); 119 | sBtnImmersible = (SwitchCompat) vHeader.findViewById(R.id.sBtn_immersible); 120 | sBtnLight = (SwitchCompat) vHeader.findViewById(R.id.sBtn_light); 121 | sBtnLine = (SwitchCompat) vHeader.findViewById(R.id.sBtn_line); 122 | lLayoutAlpha = (LinearLayout) vHeader.findViewById(R.id.lLayout_alpha); 123 | sBarAlpha = (SeekBar) vHeader.findViewById(R.id.sBar_alpha); 124 | tvStatusAlpha = (TextView) vHeader.findViewById(R.id.tv_statusAlpha); 125 | initView(); 126 | setDrawerList(); 127 | initData(); 128 | } 129 | 130 | private void setDrawerList() { 131 | List listDrawer = new ArrayList<>(); 132 | listDrawer.add(new DrawerEntity("AriesHoo", "点击跳转GitHub个人主页", "https://github.com/AriesHoo")); 133 | listDrawer.add(new DrawerEntity("FastLib-快速开发库", "点击跳转GitHub项目页", "https://github.com/AriesHoo/FastLib/blob/master/README.md")); 134 | listDrawer.add(new DrawerEntity("UIWidget-常用UI控件库", "点击跳转GitHub项目页", "https://github.com/AriesHoo/UIWidget/blob/master/README.md")); 135 | listDrawer.add(new DrawerEntity("TitleBarView-标题栏控件", "点击跳转GitHub项目页", "https://github.com/AriesHoo/TitleBarView/blob/master/README.md")); 136 | listDrawer.add(new DrawerEntity("简书-TitleBarView解析", "点击跳转简书", "http://www.jianshu.com/p/34ace867b29f")); 137 | DrawerHelper.getInstance().initRecyclerView(mContext, mRecyclerViewDrawer, listDrawer); 138 | } 139 | 140 | private void initData() { 141 | List list = new ArrayList<>(); 142 | list.add(new TitleEntity("TitleBarView与底部EditText结合", "点击查看示例", TitleEditActivity.class)); 143 | list.add(new TitleEntity("白色主题", "点击切换白色主题", android.R.color.white)); 144 | list.add(new TitleEntity("红色主题", "点击切换红色主题", android.R.color.holo_red_light)); 145 | list.add(new TitleEntity("橙色主题", "点击切换橙色主题", android.R.color.holo_orange_light)); 146 | list.add(new TitleEntity("绿色主题", "点击切换绿色主题", android.R.color.holo_green_light)); 147 | list.add(new TitleEntity("蓝色主题", "点击切换蓝色主题", android.R.color.holo_blue_light)); 148 | list.add(new TitleEntity("紫色主题", "点击切换紫色主题", android.R.color.holo_purple)); 149 | mAdapter.setHeaderView(vHeader); 150 | mAdapter.setNewData(list); 151 | ViewUtil.getInstance().setViewHeight(fLayoutDrawer, (int) (getResources().getDimension(R.dimen.dp_drawer_header)) + titleBar.getStatusBarHeight()); 152 | } 153 | 154 | private void initView() { 155 | canImmersible = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; 156 | canLight = canImmersible; 157 | if (!canImmersible) { 158 | sBtnImmersible.setChecked(false); 159 | sBtnImmersible.setClickable(false); 160 | sBtnLight.setChecked(false); 161 | sBtnImmersible.setText("4.4以下不支持沉浸状态栏"); 162 | sBtnLight.setClickable(false); 163 | } 164 | if (!canLight) { 165 | sBtnLight.setChecked(false); 166 | sBtnLight.setClickable(false); 167 | sBtnLight.setText("4.4以下不支持全透明"); 168 | sBarAlpha.setClickable(false); 169 | lLayoutAlpha.setVisibility(View.GONE); 170 | } 171 | sBarAlpha.setMax(255); 172 | sBtnImmersible.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 173 | @Override 174 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 175 | isImmersible = isChecked; 176 | titleBar.setImmersible(mContext, isImmersible, isLight);//一般情况下使用 177 | titleBarDrawer.setImmersible(mContext, isImmersible, isLight); 178 | sBtnImmersible.setText(isChecked ? "沉浸" : "不沉浸"); 179 | if (!isImmersible) { 180 | sBtnLight.setChecked(false); 181 | sBarAlpha.setProgress(255); 182 | StatusBarUtil.setStatusBarDarkMode(mContext); 183 | } else { 184 | if (isWhite) { 185 | StatusBarUtil.setStatusBarLightMode(mContext); 186 | } else { 187 | StatusBarUtil.setStatusBarDarkMode(mContext); 188 | } 189 | } 190 | } 191 | }); 192 | sBtnLight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 193 | @Override 194 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 195 | isLight = isChecked; 196 | if (isLight) { 197 | sBtnImmersible.setChecked(true); 198 | sBarAlpha.setProgress(0); 199 | } else { 200 | sBarAlpha.setProgress(102); 201 | } 202 | titleBar.setImmersible(mContext, isImmersible, isLight);//一般情况下使用 203 | titleBarDrawer.setImmersible(mContext, isImmersible, isLight); 204 | if (!isImmersible) { 205 | StatusBarUtil.setStatusBarDarkMode(mContext); 206 | } else { 207 | if (isWhite) { 208 | StatusBarUtil.setStatusBarLightMode(mContext); 209 | } else { 210 | StatusBarUtil.setStatusBarDarkMode(mContext); 211 | } 212 | } 213 | sBtnLight.setText(isChecked ? "状态栏全透明" : "状态栏半透明"); 214 | } 215 | }); 216 | sBtnLine.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 217 | @Override 218 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 219 | titleBar.setDividerVisible(isChecked); 220 | sBtnLine.setText(isChecked ? "显示下划线" : "隐藏下划线"); 221 | } 222 | }); 223 | sBarAlpha.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 224 | @Override 225 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 226 | tvStatusAlpha.setText(progress + ""); 227 | mAlpha = progress; 228 | if (canImmersible) { 229 | sBtnImmersible.setChecked(mAlpha < 230); 230 | } 231 | if (canLight) { 232 | sBtnLight.setChecked(mAlpha == 0); 233 | } 234 | titleBar.setStatusAlpha(mAlpha); 235 | if (mAlpha > 230 && isWhite) { 236 | StatusBarUtil.setStatusBarDarkMode(mContext); 237 | } else { 238 | if (isWhite) { 239 | StatusBarUtil.setStatusBarLightMode(mContext); 240 | } 241 | } 242 | } 243 | 244 | @Override 245 | public void onStartTrackingTouch(SeekBar seekBar) { 246 | 247 | } 248 | 249 | @Override 250 | public void onStopTrackingTouch(SeekBar seekBar) { 251 | 252 | } 253 | }); 254 | drawerRoot.setDrawerListener(new DrawerLayout.SimpleDrawerListener() { 255 | @Override 256 | public void onDrawerOpened(View drawerView) { 257 | super.onDrawerOpened(drawerView); 258 | if (type > 0) { 259 | StatusBarUtil.setStatusBarDarkMode(mContext); 260 | } 261 | } 262 | 263 | @Override 264 | public void onDrawerClosed(View drawerView) { 265 | super.onDrawerClosed(drawerView); 266 | if (type > 0) { 267 | if (isWhite && isImmersible) { 268 | StatusBarUtil.setStatusBarLightMode(mContext); 269 | } else { 270 | StatusBarUtil.setStatusBarDarkMode(mContext); 271 | } 272 | } 273 | } 274 | }); 275 | if (canLight && Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { 276 | sBtnLight.setChecked(false); 277 | sBarAlpha.setProgress(titleBar.DEFAULT_STATUS_BAR_ALPHA); 278 | } else { 279 | sBarAlpha.setProgress(0); 280 | } 281 | } 282 | 283 | @Override 284 | protected void onItemClicked(BaseQuickAdapter adapter, View view, int position) { 285 | super.onItemClicked(adapter, view, position); 286 | TitleEntity entity = adapter.getItem(position); 287 | if (entity.colorRes != 0) { 288 | isWhite = entity.colorRes == android.R.color.white; 289 | titleBar.setBackgroundResource(entity.colorRes); 290 | titleBar.setLeftTextDrawable(isWhite ? R.drawable.ic_arrow_left : R.drawable.ic_arrow_back_white); 291 | titleBar.setRightTextDrawable(isWhite ? R.drawable.ic_menu : R.drawable.ic_menu_white); 292 | titleBar.setTitleMainTextColor(isWhite ? getResources().getColor(R.color.colorTextBlack) : Color.WHITE); 293 | titleBar.setTitleSubTextColor(isWhite ? getResources().getColor(R.color.colorTextBlack) : Color.WHITE); 294 | if (type > 0 && isImmersible) { 295 | if (isWhite) { 296 | StatusBarUtil.setStatusBarLightMode(mContext); 297 | } else { 298 | StatusBarUtil.setStatusBarDarkMode(mContext); 299 | } 300 | } 301 | } else if (entity.activity != null) { 302 | startActivity(entity.activity); 303 | } 304 | } 305 | 306 | @Override 307 | public void onBackPressed() { 308 | if (drawerRoot.isDrawerOpen(svSlide)) { 309 | drawerRoot.closeDrawer(svSlide); 310 | } else { 311 | super.onBackPressed(); 312 | } 313 | } 314 | } 315 | -------------------------------------------------------------------------------- /app/src/main/java/com/aries/title/TitleEditActivity.java: -------------------------------------------------------------------------------- 1 | package com.aries.title; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.aries.title.base.BaseActivity; 6 | 7 | /** 8 | * Created: AriesHoo on 2017/7/14 15:57 9 | * Function: titleBar与底部状态栏使用 10 | * Desc: 11 | */ 12 | public class TitleEditActivity extends BaseActivity { 13 | 14 | @Override 15 | protected void setTitleBar() { 16 | } 17 | 18 | @Override 19 | protected int getLayout() { 20 | return R.layout.activity_title_edit; 21 | } 22 | 23 | @Override 24 | protected void initView(Bundle var1) { 25 | getSupportFragmentManager().beginTransaction().add(R.id.lLayout_content, TitleFragment.newInstance()).commit(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/aries/title/TitleFragment.java: -------------------------------------------------------------------------------- 1 | package com.aries.title; 2 | 3 | import android.graphics.Color; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | import com.aries.ui.view.radius.RadiusTextView; 12 | import com.aries.ui.view.title.TitleBarView; 13 | 14 | import butterknife.BindView; 15 | import butterknife.ButterKnife; 16 | import butterknife.Unbinder; 17 | 18 | /** 19 | * Created: AriesHoo on 2017/8/17 15:09 20 | * Function: 带底部输入框处理方案 21 | * Desc: 22 | */ 23 | public class TitleFragment extends Fragment { 24 | 25 | @BindView(R.id.titleBar) TitleBarView titleBar; 26 | @BindView(R.id.rtv_send) RadiusTextView rtvSend; 27 | private Unbinder unbinder; 28 | private View mContentView; 29 | 30 | public static TitleFragment newInstance() { 31 | Bundle args = new Bundle(); 32 | TitleFragment fragment = new TitleFragment(); 33 | fragment.setArguments(args); 34 | return fragment; 35 | } 36 | 37 | @Nullable 38 | @Override 39 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 40 | mContentView = inflater.inflate(R.layout.fragment_title, container, false); 41 | unbinder = ButterKnife.bind(this, mContentView); 42 | initView(); 43 | return mContentView; 44 | } 45 | 46 | private void initView() { 47 | titleBar.setTitleMainText(getClass().getSimpleName()) 48 | .setTitleMainTextColor(Color.WHITE) 49 | .setLeftTextDrawable(R.drawable.ic_arrow_back_white) 50 | .setOnLeftTextClickListener(new View.OnClickListener() { 51 | @Override 52 | public void onClick(View v) { 53 | getActivity().onBackPressed(); 54 | } 55 | }) 56 | .setBackgroundResource(android.R.color.holo_purple); 57 | titleBar.setStatusBarLightMode(false); 58 | 59 | // //底部有输入框时使用--最后一个参数false 60 | // titleBar.setImmersible(getActivity(), true, true, false); 61 | // //设置根布局setFitsSystemWindows(true) 62 | // mContentView.setFitsSystemWindows(true); 63 | // //根布局背景色保持和titleBar背景一致 64 | // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 65 | // mContentView.setBackground(titleBar.getBackground()); 66 | // } else { 67 | // mContentView.setBackgroundResource(android.R.color.holo_purple); 68 | // } 69 | //或者 70 | titleBar.setBottomEditTextControl(); 71 | } 72 | 73 | @Override 74 | public void onDestroyView() { 75 | super.onDestroyView(); 76 | unbinder.unbind(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/com/aries/title/WebViewActivity.java: -------------------------------------------------------------------------------- 1 | package com.aries.title; 2 | 3 | import android.app.Activity; 4 | import android.content.DialogInterface; 5 | import android.content.Intent; 6 | import android.graphics.Bitmap; 7 | import android.graphics.Color; 8 | import android.os.Bundle; 9 | import android.support.v7.app.AlertDialog; 10 | import android.util.Log; 11 | import android.view.Gravity; 12 | import android.view.KeyEvent; 13 | import android.view.View; 14 | import android.webkit.WebChromeClient; 15 | import android.webkit.WebView; 16 | import android.webkit.WebViewClient; 17 | import android.widget.LinearLayout; 18 | 19 | import com.aries.title.base.BaseActivity; 20 | import com.aries.title.util.AppUtil; 21 | import com.just.library.AgentWeb; 22 | import com.just.library.ChromeClientCallbackManager; 23 | 24 | import butterknife.BindView; 25 | 26 | public class WebViewActivity extends BaseActivity { 27 | 28 | @BindView(R.id.lLayout_containerWebView) LinearLayout lLayoutContainer; 29 | 30 | private String url = ""; 31 | private AlertDialog mAlertDialog; 32 | protected AgentWeb mAgentWeb; 33 | 34 | public static void start(Activity mActivity, String url) { 35 | Bundle bundle = new Bundle(); 36 | bundle.putString("url", url); 37 | AppUtil.startActivity(mActivity, WebViewActivity.class, bundle); 38 | } 39 | 40 | @Override 41 | protected void setTitleBar() { 42 | titleBar.addLeftAction(titleBar.new ImageAction(R.drawable.ic_close, new View.OnClickListener() { 43 | @Override 44 | public void onClick(View v) { 45 | showDialog(); 46 | } 47 | })); 48 | titleBar.setRightTextDrawable(R.drawable.ic_share); 49 | titleBar.setOnRightTextClickListener(new View.OnClickListener() { 50 | @Override 51 | public void onClick(View v) { 52 | AppUtil.shareShareText(mContext, url); 53 | } 54 | }); 55 | titleBar.setTitleMainTextMarquee(true); 56 | } 57 | 58 | @Override 59 | protected int getLayout() { 60 | return R.layout.activity_web_view; 61 | } 62 | 63 | @Override 64 | protected void initView(Bundle bundle) { 65 | url = getIntent().getStringExtra("url"); 66 | mAgentWeb = AgentWeb.with(this)// 67 | .setAgentWebParent(lLayoutContainer, new LinearLayout.LayoutParams(-1, -1))// 68 | .useDefaultIndicator()// 69 | .defaultProgressBarColor() 70 | .setReceivedTitleCallback(mCallback) 71 | .setWebChromeClient(mWebChromeClient) 72 | .setWebViewClient(mWebViewClient) 73 | .setSecutityType(AgentWeb.SecurityType.strict) 74 | .createAgentWeb()// 75 | .ready() 76 | .go(url); 77 | 78 | mAgentWeb.getLoader().loadUrl(url); 79 | } 80 | 81 | private void showDialog() { 82 | if (mAlertDialog == null) 83 | mAlertDialog = new AlertDialog.Builder(this) 84 | .setTitle("温馨提示") 85 | .setMessage("您确定要关闭该页面吗?") 86 | .setNegativeButton("再逛逛", new DialogInterface.OnClickListener() { 87 | @Override 88 | public void onClick(DialogInterface dialog, int which) { 89 | if (mAlertDialog != null) 90 | mAlertDialog.dismiss(); 91 | } 92 | })// 93 | .setPositiveButton("关闭", new DialogInterface.OnClickListener() { 94 | @Override 95 | public void onClick(DialogInterface dialog, int which) { 96 | 97 | if (mAlertDialog != null) 98 | mAlertDialog.dismiss(); 99 | mContext.finish(); 100 | } 101 | }).create(); 102 | mAlertDialog.show(); 103 | //show之后可获取对应Button对象设置文本颜色--show之前获取对象为null 104 | mAlertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(Color.RED); 105 | // mAlertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(Color.GREEN); 106 | // mAlertDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setTextColor(Color.BLUE); 107 | } 108 | 109 | private WebViewClient mWebViewClient = new WebViewClient() { 110 | @Override 111 | public void onPageStarted(WebView view, String url, Bitmap favicon) { 112 | //do you work 113 | Log.i("Info", "BaseWebActivity onPageStarted"); 114 | } 115 | }; 116 | private WebChromeClient mWebChromeClient = new WebChromeClient() { 117 | @Override 118 | public void onProgressChanged(WebView view, int newProgress) { 119 | //do you work 120 | // Log.i("Info","progress:"+newProgress); 121 | } 122 | }; 123 | 124 | 125 | private ChromeClientCallbackManager.ReceivedTitleCallback mCallback = new ChromeClientCallbackManager.ReceivedTitleCallback() { 126 | @Override 127 | public void onReceivedTitle(WebView view, String title) { 128 | titleBar.setTitleMainText(title); 129 | } 130 | }; 131 | 132 | @Override 133 | public boolean onKeyDown(int keyCode, KeyEvent event) { 134 | if (mAgentWeb.handleKeyEvent(keyCode, event)) { 135 | return true; 136 | } 137 | return super.onKeyDown(keyCode, event); 138 | } 139 | 140 | @Override 141 | public void onBackPressed() { 142 | if (mAgentWeb.back()) { 143 | return; 144 | } 145 | super.onBackPressed(); 146 | } 147 | 148 | @Override 149 | protected void onPause() { 150 | mAgentWeb.getWebLifeCycle().onPause(); 151 | super.onPause(); 152 | 153 | } 154 | 155 | @Override 156 | protected void onResume() { 157 | mAgentWeb.getWebLifeCycle().onResume(); 158 | super.onResume(); 159 | if (titleBar != null) { 160 | titleBar.getTextView(Gravity.CENTER | Gravity.TOP).requestFocus(); 161 | } 162 | } 163 | 164 | @Override 165 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 166 | mAgentWeb.uploadFileResult(requestCode, resultCode, data); 167 | super.onActivityResult(requestCode, resultCode, data); 168 | } 169 | 170 | 171 | @Override 172 | protected void onDestroy() { 173 | super.onDestroy(); 174 | mAgentWeb.getWebLifeCycle().onDestroy(); 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /app/src/main/java/com/aries/title/adapter/DrawerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.aries.title.adapter; 2 | 3 | import android.app.Activity; 4 | 5 | import com.aries.title.R; 6 | import com.aries.title.entity.DrawerEntity; 7 | import com.chad.library.adapter.base.BaseQuickAdapter; 8 | import com.chad.library.adapter.base.BaseViewHolder; 9 | 10 | import java.util.ArrayList; 11 | 12 | /** 13 | * Created: AriesHoo on 2017/7/14 9:55 14 | * Function: Drawer 适配器 15 | * Desc: 16 | */ 17 | public class DrawerAdapter extends BaseQuickAdapter { 18 | private Activity mActivity; 19 | 20 | public DrawerAdapter(Activity mActivity) { 21 | super(R.layout.item_widget, new ArrayList()); 22 | this.mActivity = mActivity; 23 | } 24 | 25 | @Override 26 | protected void convert(BaseViewHolder helper, DrawerEntity item) { 27 | helper.setText(R.id.tv_titleWidget, item.title); 28 | helper.setText(R.id.tv_contentWidget, item.content); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/aries/title/adapter/TitleAdapter.java: -------------------------------------------------------------------------------- 1 | package com.aries.title.adapter; 2 | 3 | import android.app.Activity; 4 | 5 | import com.aries.title.R; 6 | import com.aries.title.entity.TitleEntity; 7 | import com.chad.library.adapter.base.BaseQuickAdapter; 8 | import com.chad.library.adapter.base.BaseViewHolder; 9 | 10 | import java.util.ArrayList; 11 | 12 | /** 13 | * Created: AriesHoo on 2017/7/14 9:55 14 | * Function: TitleBarView 适配器 15 | * Desc: 16 | */ 17 | public class TitleAdapter extends BaseQuickAdapter { 18 | private Activity mActivity; 19 | 20 | public TitleAdapter(Activity mActivity) { 21 | super(R.layout.item_widget, new ArrayList()); 22 | this.mActivity = mActivity; 23 | } 24 | 25 | @Override 26 | protected void convert(BaseViewHolder helper, TitleEntity item) { 27 | helper.setText(R.id.tv_titleWidget, item.title); 28 | helper.setText(R.id.tv_contentWidget, item.content); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/aries/title/base/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.aries.title.base; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.support.annotation.LayoutRes; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.aries.title.R; 11 | import com.aries.title.util.AppUtil; 12 | import com.aries.ui.view.title.TitleBarView; 13 | 14 | import butterknife.ButterKnife; 15 | import butterknife.Unbinder; 16 | 17 | /** 18 | * Created: AriesHoo on 2017/7/3 16:04 19 | * Function: title 基类 20 | * Desc: 21 | */ 22 | 23 | public abstract class BaseActivity extends AppCompatActivity { 24 | 25 | protected TitleBarView titleBar; 26 | protected Activity mContext; 27 | protected boolean mIsFirstShow = true; 28 | private Unbinder mUnBinder; 29 | protected int type = 0; 30 | protected boolean isWhite = true; 31 | protected View mContentView; 32 | 33 | protected abstract void setTitleBar(); 34 | 35 | protected boolean isShowLine() { 36 | return true; 37 | } 38 | 39 | @LayoutRes 40 | protected abstract int getLayout(); 41 | 42 | protected void loadData() { 43 | } 44 | 45 | protected void beforeSetView() { 46 | } 47 | 48 | protected void beforeInitView() { 49 | } 50 | 51 | protected abstract void initView(Bundle var1); 52 | 53 | @Override 54 | protected void onCreate(Bundle savedInstanceState) { 55 | super.onCreate(savedInstanceState); 56 | this.mContext = this; 57 | this.beforeSetView(); 58 | mContentView = View.inflate(mContext, getLayout(), null); 59 | // mContentView.setBackgroundResource(R.color.colorBackground); 60 | this.setContentView(mContentView); 61 | mUnBinder = ButterKnife.bind(this); 62 | initTitle(); 63 | this.beforeInitView(); 64 | this.initView(savedInstanceState); 65 | } 66 | 67 | protected void initTitle() { 68 | titleBar = (TitleBarView) findViewById(R.id.titleBar); 69 | if (titleBar == null) { 70 | return; 71 | } 72 | type = titleBar.getStatusBarModeType(); 73 | if (type <= 0) {//无法设置白底黑字 74 | titleBar.setStatusAlpha(102);//5.0 半透明模式alpha-102 75 | } 76 | titleBar.setTitleMainText(mContext.getClass().getSimpleName()); 77 | setTitleBar(); 78 | titleBar.setOnLeftTextClickListener(new View.OnClickListener() { 79 | @Override 80 | public void onClick(View v) { 81 | onBackPressed(); 82 | } 83 | }); 84 | setTitleLine(isShowLine()); 85 | } 86 | 87 | public void setTitleLine(boolean enable) { 88 | titleBar.setDividerVisible(enable); 89 | } 90 | 91 | public void startActivity(Activity mContext, Class activity, Bundle bundle) { 92 | AppUtil.startActivity(mContext, activity, bundle); 93 | } 94 | 95 | public void startActivity(Class activity, Bundle bundle) { 96 | startActivity(mContext, activity, bundle); 97 | } 98 | 99 | public void startActivity(Class activity) { 100 | startActivity(activity, null); 101 | } 102 | 103 | public View getRootView() { 104 | return ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0); 105 | } 106 | 107 | @Override 108 | protected void onDestroy() { 109 | super.onDestroy(); 110 | mUnBinder.unbind(); 111 | } 112 | 113 | protected void onResume() { 114 | if (this.mIsFirstShow) { 115 | this.mIsFirstShow = false; 116 | this.loadData(); 117 | } 118 | 119 | super.onResume(); 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /app/src/main/java/com/aries/title/base/BaseRecycleActivity.java: -------------------------------------------------------------------------------- 1 | package com.aries.title.base; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.widget.LinearLayoutManager; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.util.Log; 7 | import android.view.View; 8 | 9 | import com.aries.title.R; 10 | import com.chad.library.adapter.base.BaseQuickAdapter; 11 | import com.chad.library.adapter.base.BaseViewHolder; 12 | import com.chad.library.adapter.base.listener.OnItemClickListener; 13 | 14 | /** 15 | * Created: AriesHoo on 2017/7/14 9:41 16 | * Function: 有RecycleView Activity 17 | * Desc: 18 | */ 19 | public abstract class BaseRecycleActivity extends BaseActivity 20 | implements BaseQuickAdapter.RequestLoadMoreListener { 21 | 22 | protected RecyclerView mRecyclerView; 23 | protected RecyclerView.LayoutManager mLayoutManager; 24 | protected BaseQuickAdapter mAdapter; 25 | protected int DEFAULT_PAGE = 0; 26 | protected int DEFAULT_PAGE_SIZE = 10; 27 | 28 | protected abstract void loadData(int page); 29 | 30 | protected boolean setLoadMore() { 31 | return true; 32 | } 33 | 34 | protected boolean setItemClickable() { 35 | return true; 36 | } 37 | 38 | protected abstract BaseQuickAdapter getAdapter(); 39 | 40 | protected void initView(Bundle bundle) { 41 | mRecyclerView = (RecyclerView) findViewById(R.id.rv_content); 42 | if (mRecyclerView == null) { 43 | return; 44 | } 45 | initRecyclerView(); 46 | } 47 | 48 | protected void initRecyclerView() { 49 | mRecyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER); 50 | mRecyclerView.setLayoutManager(initLayoutManager()); 51 | mRecyclerView.setAdapter(initAdapter()); 52 | if (!setItemClickable()) { 53 | return; 54 | } 55 | mRecyclerView.addOnItemTouchListener(new OnItemClickListener() { 56 | @Override 57 | public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) { 58 | onItemClicked(adapter, view, position); 59 | } 60 | 61 | }); 62 | } 63 | 64 | protected RecyclerView.LayoutManager initLayoutManager() { 65 | mLayoutManager = new LinearLayoutManager(mContext); 66 | return mLayoutManager; 67 | } 68 | 69 | protected RecyclerView.Adapter initAdapter() { 70 | mAdapter = getAdapter(); 71 | if (mAdapter != null && setLoadMore()) { 72 | mAdapter.setOnLoadMoreListener(this); 73 | } 74 | return mAdapter; 75 | } 76 | 77 | protected void onItemClicked(BaseQuickAdapter adapter, View view, int position) { 78 | Log.d("onItemClicked", "onItemClicked:" + position); 79 | } 80 | 81 | @Override 82 | public void onLoadMoreRequested() { 83 | loadData(DEFAULT_PAGE++); 84 | } 85 | 86 | @Override 87 | protected void loadData() { 88 | loadData(DEFAULT_PAGE); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /app/src/main/java/com/aries/title/entity/DrawerEntity.java: -------------------------------------------------------------------------------- 1 | package com.aries.title.entity; 2 | 3 | /** 4 | * Created: AriesHoo on 2017/7/14 9:45 5 | * Function: 应用实体 6 | * Desc: 7 | */ 8 | public class DrawerEntity { 9 | 10 | public String title; 11 | public String content; 12 | public String url; 13 | 14 | public DrawerEntity(String title, String content, String url) { 15 | this.title = title; 16 | this.content = content; 17 | this.url = url; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/aries/title/entity/TitleEntity.java: -------------------------------------------------------------------------------- 1 | package com.aries.title.entity; 2 | 3 | import android.app.Activity; 4 | 5 | /** 6 | * Created: AriesHoo on 2017/7/14 9:45 7 | * Function: 应用实体 8 | * Desc: 9 | */ 10 | public class TitleEntity { 11 | 12 | public String title; 13 | public String content; 14 | public Class activity; 15 | public int colorRes; 16 | 17 | public TitleEntity(String title, String content, Class activity) { 18 | this.title = title; 19 | this.content = content; 20 | this.activity = activity; 21 | } 22 | 23 | public TitleEntity(String title, String content, int colorRes) { 24 | this.title = title; 25 | this.content = content; 26 | this.colorRes = colorRes; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/aries/title/entity/WidgetEntity.java: -------------------------------------------------------------------------------- 1 | package com.aries.title.entity; 2 | 3 | import android.app.Activity; 4 | 5 | /** 6 | * Created: AriesHoo on 2017/7/14 9:45 7 | * Function: 应用实体 8 | * Desc: 9 | */ 10 | public class WidgetEntity { 11 | 12 | public String title; 13 | public String content; 14 | public Class activity; 15 | 16 | public WidgetEntity(String title, String content, Class activity) { 17 | this.title = title; 18 | this.content = content; 19 | this.activity = activity; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/aries/title/manager/GlideManager.java: -------------------------------------------------------------------------------- 1 | package com.aries.title.manager; 2 | 3 | import android.content.Context; 4 | import android.content.res.Resources; 5 | import android.graphics.Bitmap; 6 | import android.graphics.BitmapShader; 7 | import android.graphics.Canvas; 8 | import android.graphics.Paint; 9 | import android.graphics.RectF; 10 | import android.widget.ImageView; 11 | 12 | import com.aries.title.R; 13 | import com.bumptech.glide.Glide; 14 | import com.bumptech.glide.Priority; 15 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 16 | import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 17 | import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; 18 | import com.bumptech.glide.load.resource.bitmap.CircleCrop; 19 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; 20 | import com.bumptech.glide.request.RequestOptions; 21 | 22 | import java.security.MessageDigest; 23 | 24 | 25 | /** 26 | * Created: AriesHoo on 2017-03-13 18:33 27 | * Function: Glide 工具类支持加载常规、圆角、圆形图片 28 | * Desc: 29 | */ 30 | public class GlideManager { 31 | 32 | private static int sCommonPlaceholder; 33 | private static int sCirclePlaceholder; 34 | private static int sRoundPlaceholder; 35 | 36 | 37 | static { 38 | sCommonPlaceholder = R.drawable.fast_shape_placeholder_common; 39 | sCirclePlaceholder = R.drawable.fast_shape_placeholder_circle; 40 | sRoundPlaceholder = R.drawable.fast_shape_placeholder_round; 41 | } 42 | 43 | /** 44 | * 设置圆形图片的占位图 45 | * 46 | * @param circlePlaceholder 47 | */ 48 | public static void setCirclePlaceholder(int circlePlaceholder) { 49 | sCirclePlaceholder = circlePlaceholder; 50 | } 51 | 52 | /** 53 | * 设置正常图片的占位符 54 | * 55 | * @param commonPlaceholder 56 | */ 57 | public static void setCommonPlaceholder(int commonPlaceholder) { 58 | sCommonPlaceholder = commonPlaceholder; 59 | } 60 | 61 | /** 62 | * 设置圆角图片的占位符 63 | * 64 | * @param roundPlaceholder 65 | */ 66 | public static void setsRoundPlaceholder(int roundPlaceholder) { 67 | sRoundPlaceholder = roundPlaceholder; 68 | } 69 | 70 | /** 71 | * 普通加载图片 72 | * 73 | * @param obj 74 | * @param iv 75 | * @param placeholderResource 76 | */ 77 | public static void loadImg(Object obj, ImageView iv, int placeholderResource) { 78 | Glide.with(iv.getContext()).load(obj).apply(getRequestOptions() 79 | .error(placeholderResource) 80 | .placeholder(placeholderResource) 81 | .fallback(placeholderResource) 82 | .dontAnimate()).into(iv); 83 | } 84 | 85 | public static void loadImg(Object obj, ImageView iv) { 86 | loadImg(obj, iv, sCommonPlaceholder); 87 | } 88 | 89 | /** 90 | * 加载圆形图片 91 | * 92 | * @param obj 93 | * @param iv 94 | * @param placeholderResource 占位图 95 | */ 96 | public static void loadCircleImg(Object obj, ImageView iv, int placeholderResource) { 97 | Glide.with(iv.getContext()).load(obj).apply(getRequestOptions() 98 | .error(placeholderResource) 99 | .placeholder(placeholderResource) 100 | .fallback(placeholderResource) 101 | .dontAnimate() 102 | .transform(new CircleCrop())).into(iv); 103 | } 104 | 105 | public static void loadCircleImg(Object obj, ImageView iv) { 106 | loadCircleImg(obj, iv, sCirclePlaceholder); 107 | } 108 | 109 | /** 110 | * 加载圆角图片 111 | * 112 | * @param obj 加载的图片资源 113 | * @param iv 114 | * @param dp 圆角尺寸-dp 115 | * @param placeholderResource -占位图 116 | * @param isOfficial-是否官方模式圆角 117 | */ 118 | public static void loadRoundImg(Object obj, ImageView iv, float dp, int placeholderResource, boolean isOfficial) { 119 | Glide.with(iv.getContext()).load(obj).apply(getRequestOptions() 120 | .error(placeholderResource) 121 | .placeholder(placeholderResource) 122 | .fallback(placeholderResource) 123 | .dontAnimate() 124 | .transform(isOfficial ? new RoundedCorners(dp2px(dp)) : new GlideRoundTransform(iv.getContext(), dp2px(dp)))).into(iv); 125 | } 126 | 127 | public static void loadRoundImg(Object obj, ImageView iv, float dp, boolean isOfficial) { 128 | loadRoundImg(obj, iv, dp, sRoundPlaceholder, isOfficial); 129 | } 130 | 131 | public static void loadRoundImg(Object obj, ImageView iv, float dp) { 132 | loadRoundImg(obj, iv, dp, true); 133 | } 134 | 135 | public static void loadRoundImg(Object obj, ImageView iv, boolean isOfficial) { 136 | loadRoundImg(obj, iv, 4, isOfficial); 137 | } 138 | 139 | public static void loadRoundImg(Object obj, ImageView iv) { 140 | loadRoundImg(obj, iv, true); 141 | } 142 | 143 | private static RequestOptions getRequestOptions() { 144 | RequestOptions requestOptions = new RequestOptions() 145 | .centerCrop() // 填充方式 146 | .priority(Priority.HIGH) //优先级 147 | .diskCacheStrategy(DiskCacheStrategy.ALL); //缓存策略 148 | return requestOptions; 149 | } 150 | 151 | private static int dp2px(float dipValue) { 152 | final float scale = Resources.getSystem().getDisplayMetrics().density; 153 | return (int) (dipValue * scale + 0.5f); 154 | } 155 | 156 | private static class GlideRoundTransform extends BitmapTransformation { 157 | int radius = 0; 158 | 159 | public GlideRoundTransform(Context context, int dp) { 160 | super(context); 161 | this.radius = dp; 162 | } 163 | 164 | @Override 165 | protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { 166 | return roundCrop(pool, toTransform); 167 | } 168 | 169 | private Bitmap roundCrop(BitmapPool pool, Bitmap source) { 170 | Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); 171 | if (result == null) { 172 | result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); 173 | } 174 | 175 | Canvas canvas = new Canvas(result); 176 | Paint paint = new Paint(); 177 | paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); 178 | paint.setAntiAlias(true); 179 | RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight()); 180 | canvas.drawRoundRect(rectF, radius, radius, paint); 181 | return result; 182 | } 183 | 184 | @Override 185 | public void updateDiskCacheKey(MessageDigest messageDigest) { 186 | 187 | } 188 | } 189 | } -------------------------------------------------------------------------------- /app/src/main/java/com/aries/title/util/AppUtil.java: -------------------------------------------------------------------------------- 1 | package com.aries.title.util; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.net.Uri; 7 | import android.os.Bundle; 8 | 9 | 10 | /** 11 | * Created: AriesHoo on 2017-03-14 08:54 12 | * Function: app使用工具类 13 | * Desc: 14 | */ 15 | public class AppUtil { 16 | 17 | public static void jumpMarket(Context mContext) { 18 | jumpMarket(mContext, null); 19 | } 20 | 21 | public static void jumpMarket(Context mContext, String packageName) { 22 | if (mContext == null) { 23 | return; 24 | } 25 | if (packageName == null || packageName.isEmpty()) { 26 | packageName = mContext.getPackageName(); 27 | } 28 | String mAddress = "market://details?id=" + packageName; 29 | try { 30 | Intent marketIntent = new Intent("android.intent.action.VIEW"); 31 | marketIntent.setData(Uri.parse(mAddress)); 32 | mContext.startActivity(marketIntent); 33 | } catch (Exception e) { 34 | e.printStackTrace(); 35 | } 36 | } 37 | 38 | public static void startBorwer(Context context, String url) { 39 | Intent intent = new Intent(); 40 | intent.setAction("android.intent.action.VIEW"); 41 | intent.setData(Uri.parse(url)); 42 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 43 | context.startActivity(intent); 44 | } 45 | /** 46 | * @param activity 47 | * @param bundle 48 | */ 49 | public static void startActivity(Activity mContext, Class activity, Bundle bundle) { 50 | if (mContext == null) { 51 | return; 52 | } 53 | Intent intent = new Intent(mContext, activity); 54 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 55 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); 56 | if (bundle != null) { 57 | intent.putExtras(bundle); 58 | } 59 | mContext.startActivity(intent); 60 | } 61 | 62 | public static void startActivity(Activity mContext, Class activity) { 63 | startActivity(mContext, activity, null); 64 | } 65 | 66 | public static void shareShareText(Activity mActivity, String url) { 67 | if (mActivity == null) { 68 | return; 69 | } 70 | Intent shareIntent = new Intent(); 71 | shareIntent.setAction(Intent.ACTION_SEND); 72 | shareIntent.putExtra(Intent.EXTRA_TEXT, url); 73 | shareIntent.setType("text/plain"); 74 | //设置分享列表的标题,并且每次都显示分享列表 75 | mActivity.startActivity(Intent.createChooser(shareIntent, "分享到")); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/com/aries/title/util/ViewUtil.java: -------------------------------------------------------------------------------- 1 | package com.aries.title.util; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | import android.view.ViewParent; 6 | import android.widget.FrameLayout; 7 | import android.widget.LinearLayout; 8 | import android.widget.RelativeLayout; 9 | import android.widget.TableLayout; 10 | 11 | /** 12 | * Created: AriesHoo on 2017-01-17 12:59 13 | * Function: 视图帮助类 14 | * Desc: 15 | */ 16 | public class ViewUtil { 17 | private static volatile ViewUtil instance; 18 | 19 | private ViewUtil() { 20 | } 21 | 22 | public static ViewUtil getInstance() { 23 | if (instance == null) { 24 | synchronized (ViewUtil.class) { 25 | if (instance == null) { 26 | instance = new ViewUtil(); 27 | } 28 | } 29 | } 30 | return instance; 31 | } 32 | 33 | /** 34 | * 获取视图的宽度 35 | * 36 | * @param mView 37 | * @return 38 | */ 39 | public int getWidth(View mView) { 40 | if (mView == null) { 41 | return 0; 42 | } 43 | int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); 44 | int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); 45 | mView.measure(w, h); 46 | int width = mView.getMeasuredWidth(); 47 | return width; 48 | } 49 | 50 | /** 51 | * 获取视图高度 52 | * 53 | * @param mView 54 | * @return 55 | */ 56 | public int getHeight(View mView) { 57 | if (mView == null) { 58 | return 0; 59 | } 60 | int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); 61 | int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); 62 | mView.measure(w, h); 63 | int height = mView.getMeasuredHeight(); 64 | return height; 65 | } 66 | 67 | /** 68 | * 设置视图的宽高 69 | * 70 | * @param view 71 | * @param width 72 | * @param height 73 | */ 74 | public void setViewWidthAndHeight(View view, int width, int height) { 75 | if (view == null) { 76 | return; 77 | } 78 | ViewGroup.LayoutParams lp = view.getLayoutParams(); 79 | lp.width = width; 80 | lp.height = height; 81 | view.setLayoutParams(lp); 82 | } 83 | 84 | public void setViewWidth(View view, int width) { 85 | if (view == null) { 86 | return; 87 | } 88 | ViewGroup.LayoutParams lp = view.getLayoutParams(); 89 | lp.width = width; 90 | view.setLayoutParams(lp); 91 | } 92 | 93 | public void setViewHeight(View view, int height) { 94 | if (view == null) { 95 | return; 96 | } 97 | ViewGroup.LayoutParams lp = view.getLayoutParams(); 98 | lp.height = height; 99 | view.setLayoutParams(lp); 100 | } 101 | 102 | /** 103 | * 设置View的Margin 104 | * 105 | * @param view 106 | * @param left 107 | * @param top 108 | * @param right 109 | * @param bottom 110 | * @param width 111 | * @param height 112 | */ 113 | public void setViewMargin(View view, int left, int top, int right, int bottom, int width, int height) { 114 | if (view == null) { 115 | return; 116 | } 117 | ViewParent parent = view.getParent(); 118 | if (parent == null) { 119 | return; 120 | } 121 | ViewGroup.MarginLayoutParams lp; 122 | if (parent instanceof LinearLayout) { 123 | lp = new LinearLayout.LayoutParams(width, height); 124 | } else if (parent instanceof RelativeLayout) { 125 | lp = new RelativeLayout.LayoutParams(width, height); 126 | } else if (parent instanceof FrameLayout) { 127 | lp = new FrameLayout.LayoutParams(width, height); 128 | } else { 129 | lp = new TableLayout.LayoutParams(width, height); 130 | } 131 | if (lp != null) { 132 | lp.setMargins(left, top, right, bottom); 133 | view.setLayoutParams(lp); 134 | } 135 | } 136 | 137 | public void setViewMargin(View view, int left, int top, int right, int bottom) { 138 | if (view == null) { 139 | return; 140 | } 141 | setViewMargin(view, left, top, right, bottom, getWidth(view), getHeight(view)); 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_arrow_back_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AriesHoo/TitleBarView/70e9729a232c66a00a05456f35839f4b6b90c946/app/src/main/res/drawable-xhdpi/ic_arrow_back_white.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_arrow_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AriesHoo/TitleBarView/70e9729a232c66a00a05456f35839f4b6b90c946/app/src/main/res/drawable-xhdpi/ic_arrow_left.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_arrow_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AriesHoo/TitleBarView/70e9729a232c66a00a05456f35839f4b6b90c946/app/src/main/res/drawable-xhdpi/ic_arrow_right.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_close.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AriesHoo/TitleBarView/70e9729a232c66a00a05456f35839f4b6b90c946/app/src/main/res/drawable-xhdpi/ic_menu.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_menu_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AriesHoo/TitleBarView/70e9729a232c66a00a05456f35839f4b6b90c946/app/src/main/res/drawable-xhdpi/ic_menu_white.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_share.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/fast_shape_placeholder_circle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/fast_shape_placeholder_common.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/fast_shape_placeholder_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_title_edit.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_web_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_title.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 15 | 16 | 26 | 27 | 43 | 44 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_widget.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 21 | 22 | 32 | 33 | 36 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_drawer.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 16 | 17 | 22 | 23 | 24 | 30 | 31 | 38 | 39 | 47 | 48 | 53 | 54 | 55 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_recycle_view.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_title.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_title_bar.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_title_header.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | 17 | 18 | 19 | 28 | 29 | 30 | 31 | 40 | 41 | 42 | 43 | 44 | 53 | 54 | 55 | 56 | 57 | 64 | 65 | 71 | 72 | 78 | 79 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #393939 6 | 7 | #DCDCDC 8 | #f8f8f8 9 | #FFFFFF 10 | #333333 11 | #636363 12 | #ffffff 13 | #dcdcdc 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 0.5dp 6 | 8dp 7 | 10dp 8 | 110dp 9 | 14sp 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | TitleBarView 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 18 | 19 | 23 | 24 | 27 | 28 | 31 | 32 | 36 | 37 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | apply from: 'buildConfig.gradle' 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.3' 9 | classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' 10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | jcenter() 19 | maven { url "https://jitpack.io" } 20 | } 21 | } 22 | 23 | task clean(type: Delete) { 24 | delete rootProject.buildDir 25 | } 26 | -------------------------------------------------------------------------------- /buildConfig.gradle: -------------------------------------------------------------------------------- 1 | ext{ 2 | compileSdkVersion = 25 3 | buildToolsVersion = "25.0.2" 4 | 5 | minSdkVersion = 16 6 | targetSdkVersion = 25 7 | 8 | supportVersion = "25.3.1" 9 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | 4 | android { 5 | compileSdkVersion 25 6 | buildToolsVersion "25.0.2" 7 | 8 | defaultConfig { 9 | minSdkVersion 11 10 | targetSdkVersion 25 11 | versionCode 20 12 | versionName "2.0.0" 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | 23 | //以下为配置library注释在打包jar后保留 24 | 25 | // 打包源码jar 26 | task sourcesJar(type: Jar) { 27 | from android.sourceSets.main.java.srcDirs 28 | classifier = 'sources' 29 | } 30 | task javadoc(type: Javadoc) { 31 | failOnError false 32 | source = android.sourceSets.main.java.sourceFiles 33 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 34 | classpath += configurations.compile 35 | } 36 | // 打包文档jar 37 | task javadocJar(type: Jar, dependsOn: javadoc) { 38 | classifier = 'javadoc' 39 | from javadoc.destinationDir 40 | } 41 | artifacts { 42 | archives sourcesJar 43 | archives javadocJar 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /library/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\YSD\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 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /library/src/main/java/com/aries/ui/util/KeyboardUtil.java: -------------------------------------------------------------------------------- 1 | package com.aries.ui.util; 2 | 3 | import android.app.Activity; 4 | import android.app.Dialog; 5 | import android.graphics.Rect; 6 | import android.os.Build; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.view.ViewTreeObserver; 10 | import android.view.Window; 11 | import android.view.WindowManager; 12 | 13 | /** 14 | * Created: AriesHoo on 2017/8/17 11:51 15 | * Function:解决底部输入框和软键盘的问题 16 | * Desc: 17 | */ 18 | public class KeyboardUtil { 19 | 20 | private Activity mActivity; 21 | private Window mWindow; 22 | private View mDecorView; 23 | private View mContentView; 24 | private boolean mFlag = false; 25 | private int mKeyMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED; 26 | 27 | public static KeyboardUtil with(Activity activity) { 28 | if (activity == null) 29 | throw new IllegalArgumentException("Activity不能为null"); 30 | return new KeyboardUtil(activity); 31 | } 32 | 33 | private KeyboardUtil(Activity activity) { 34 | this(activity, ((ViewGroup) activity.getWindow().getDecorView().findViewById(android.R.id.content)).getChildAt(0)); 35 | } 36 | 37 | private KeyboardUtil(Activity activity, View contentView) { 38 | this(activity, null, "", contentView); 39 | } 40 | 41 | private KeyboardUtil(Activity activity, Dialog dialog, String tag) { 42 | this(activity, dialog, tag, dialog.getWindow().findViewById(android.R.id.content)); 43 | } 44 | 45 | private KeyboardUtil(Activity activity, Dialog dialog, String tag, View contentView) { 46 | this.mActivity = activity; 47 | this.mWindow = dialog != null ? dialog.getWindow() : activity.getWindow(); 48 | this.mDecorView = activity.getWindow().getDecorView(); 49 | this.mContentView = contentView != null ? contentView 50 | : mWindow.getDecorView().findViewById(android.R.id.content); 51 | if (!mContentView.equals(mDecorView.findViewById(android.R.id.content))) 52 | this.mFlag = true; 53 | } 54 | 55 | private KeyboardUtil(Activity activity, Window window) { 56 | this.mActivity = activity; 57 | this.mWindow = window; 58 | this.mDecorView = activity.getWindow().getDecorView(); 59 | ViewGroup frameLayout = (ViewGroup) mWindow.getDecorView().findViewById(android.R.id.content); 60 | if (frameLayout.getChildAt(0) != null) { 61 | this.mFlag = true; 62 | } 63 | this.mContentView = frameLayout.getChildAt(0) != null ? frameLayout.getChildAt(0) : frameLayout; 64 | } 65 | 66 | /** 67 | * 监听layout变化 68 | */ 69 | public void setEnable() { 70 | setEnable(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN 71 | | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); 72 | } 73 | 74 | /** 75 | * 设置监听 76 | * 77 | * @param mode 78 | */ 79 | public void setEnable(int mode) { 80 | mWindow.setSoftInputMode(mode); 81 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 82 | // 当在一个视图树中全局布局发生改变或者视图树中的某个视图的可视状态发生改变时,所要调用的回调函数的接口类 83 | mDecorView.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener); 84 | } 85 | } 86 | 87 | /** 88 | * 取消监听 89 | */ 90 | public void setDisable() { 91 | setDisable(mKeyMode); 92 | } 93 | 94 | /** 95 | * 取消监听 96 | * 97 | * @param mode 98 | */ 99 | public void setDisable(int mode) { 100 | mWindow.setSoftInputMode(mode); 101 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 102 | mDecorView.getViewTreeObserver().removeOnGlobalLayoutListener(onGlobalLayoutListener); 103 | } 104 | } 105 | 106 | /** 107 | * 设置View变化监听 108 | */ 109 | private ViewTreeObserver.OnGlobalLayoutListener onGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() { 110 | @Override 111 | public void onGlobalLayout() { 112 | Rect r = new Rect(); 113 | mDecorView.getWindowVisibleDisplayFrame(r); //获取当前窗口可视区域大小的 114 | int height = mDecorView.getContext().getResources().getDisplayMetrics().heightPixels; //获取屏幕密度,不包含导航栏 115 | int diff = height - r.bottom; 116 | if (diff >= 0) { 117 | if (mFlag || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)) { 118 | mContentView.setPadding(0, mContentView.getPaddingTop(), 0, diff); 119 | } else { 120 | mContentView.setPadding(0, mContentView.getPaddingTop(), 121 | 0, diff); 122 | } 123 | } 124 | } 125 | }; 126 | } 127 | -------------------------------------------------------------------------------- /library/src/main/java/com/aries/ui/util/RomUtil.java: -------------------------------------------------------------------------------- 1 | package com.aries.ui.util; 2 | 3 | import android.os.Build; 4 | import android.text.TextUtils; 5 | 6 | import java.lang.reflect.Method; 7 | 8 | /** 9 | * Created: AriesHoo on 2017/8/17 13:45 10 | * Function: 手机ROM工具类 11 | * Desc: 12 | */ 13 | public class RomUtil { 14 | 15 | private static final String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name"; 16 | private static final String KEY_EMUI_VERSION_NAME = "ro.build.version.emui"; 17 | 18 | 19 | /** 20 | * 判断是否为MIUI 21 | * 22 | * @return 23 | */ 24 | public static boolean isMIUI() { 25 | String property = getSystemProperty(KEY_MIUI_VERSION_NAME, ""); 26 | return !TextUtils.isEmpty(property); 27 | } 28 | 29 | /** 30 | * 获取MUI版本 31 | * 32 | * @return 33 | */ 34 | public static String getMIUIVersion() { 35 | return isMIUI() ? getSystemProperty(KEY_MIUI_VERSION_NAME, "") : ""; 36 | } 37 | 38 | /** 39 | * 获取MIUI版本-数字用于大小判断 40 | * 41 | * @return 42 | */ 43 | public static int getMIUIVersionCode() { 44 | int code = -1; 45 | String property = getMIUIVersion(); 46 | try { 47 | property = property.trim().toUpperCase().replace("V", ""); 48 | code = Integer.parseInt(property); 49 | } catch (Exception e) { 50 | e.printStackTrace(); 51 | } 52 | return code; 53 | } 54 | 55 | /** 56 | * 判断是否为EMUI 57 | * 58 | * @return 59 | */ 60 | public static boolean isEMUI() { 61 | String property = getSystemProperty(KEY_EMUI_VERSION_NAME, ""); 62 | return !TextUtils.isEmpty(property); 63 | } 64 | 65 | 66 | /** 67 | * 获取EMUI的版本 68 | * 69 | * @return 70 | */ 71 | public static String getEMUIVersion() { 72 | return isEMUI() ? getSystemProperty(KEY_EMUI_VERSION_NAME, "") : ""; 73 | } 74 | 75 | /** 76 | * 判断是否为Flyme 77 | * 78 | * @return 79 | */ 80 | public static boolean isFlyme() { 81 | return Build.DISPLAY.toLowerCase().contains("flyme"); 82 | } 83 | 84 | /** 85 | * 获取Flyme的版本 86 | * 87 | * @return 88 | */ 89 | public static String getFlymeVersion() { 90 | return isFlyme() ? Build.DISPLAY : ""; 91 | } 92 | 93 | /** 94 | * 获取Flyme版本号 95 | * 96 | * @return 97 | */ 98 | public static int getFlymeVersionCode() { 99 | int code = 0; 100 | String version = getFlymeVersion(); 101 | if (!TextUtils.isEmpty(version)) { 102 | if (version.toLowerCase().contains("os")) { 103 | code = Integer.valueOf(version.substring(9, 10)); 104 | } else { 105 | code = Integer.valueOf(version.substring(6, 7)); 106 | } 107 | } 108 | return code; 109 | } 110 | 111 | 112 | /** 113 | * 通过反射获取系统属性 114 | * 115 | * @param key 116 | * @param defaultValue 117 | * @return 118 | */ 119 | public static String getSystemProperty(String key, String defaultValue) { 120 | try { 121 | Class clz = Class.forName("android.os.SystemProperties"); 122 | Method get = clz.getMethod("get", String.class, String.class); 123 | return (String) get.invoke(clz, key, defaultValue); 124 | } catch (Exception e) { 125 | e.printStackTrace(); 126 | } 127 | return defaultValue; 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /library/src/main/java/com/aries/ui/util/StatusBarUtil.java: -------------------------------------------------------------------------------- 1 | package com.aries.ui.util; 2 | 3 | import android.app.Activity; 4 | import android.os.Build; 5 | import android.view.View; 6 | import android.view.Window; 7 | import android.view.WindowManager; 8 | 9 | import java.lang.reflect.Field; 10 | import java.lang.reflect.Method; 11 | 12 | 13 | /** 14 | * Created: AriesHoo on 2017/7/17 9:52 15 | * Function: 状态栏工具类(状态栏文字颜色) 16 | * Desc: 17 | */ 18 | public class StatusBarUtil { 19 | 20 | public static final int STATUS_BAR_TYPE_DEFAULT = 0; 21 | public static final int STATUS_BAR_TYPE_MI_UI = 1; 22 | public static final int STATUS_BAR_TYPE_FLY_ME = 2; 23 | public static final int STATUS_BAR_TYPE_ANDROID_M = 3; 24 | 25 | /** 26 | * 设置状态栏浅色模式--黑色字体图标, 27 | * 28 | * @param activity 29 | * @return 30 | */ 31 | public static int setStatusBarLightMode(Activity activity) { 32 | int result = STATUS_BAR_TYPE_DEFAULT; 33 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 34 | //MIUI 9版本开始状态栏文字颜色恢复为系统原生方案-为防止反复修改先进行6.0方案 35 | if (setStatusBarModeForAndroidM(activity.getWindow(), true)) { 36 | result = STATUS_BAR_TYPE_ANDROID_M; 37 | } 38 | if (setStatusBarModeForMIUI(activity.getWindow(), true)) { 39 | result = STATUS_BAR_TYPE_MI_UI; 40 | } else if (setStatusBarModeForFlyMe(activity.getWindow(), true)) { 41 | result = STATUS_BAR_TYPE_FLY_ME; 42 | } 43 | } 44 | return result; 45 | } 46 | 47 | /** 48 | * 设置状态栏深色模式--白色字体图标, 49 | * 50 | * @param activity 51 | * @return 52 | */ 53 | public static int setStatusBarDarkMode(Activity activity) { 54 | int result = STATUS_BAR_TYPE_DEFAULT; 55 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 56 | //MIUI 9版本开始状态栏文字颜色恢复为系统原生方案-为防止反复修改先进行6.0方案 57 | if (setStatusBarModeForAndroidM(activity.getWindow(), false)) { 58 | result = STATUS_BAR_TYPE_ANDROID_M; 59 | } 60 | if (setStatusBarModeForMIUI(activity.getWindow(), false)) { 61 | result = STATUS_BAR_TYPE_MI_UI; 62 | } else if (setStatusBarModeForFlyMe(activity.getWindow(), false)) { 63 | result = STATUS_BAR_TYPE_FLY_ME; 64 | } 65 | } 66 | return result; 67 | } 68 | 69 | /** 70 | * 设置状态栏字体图标为深色,需要MIUIV6以上 71 | * 72 | * @param window 需要设置的窗口 73 | * @param darkText 是否把状态栏字体及图标颜色设置为深色 74 | * @return boolean 成功执行返回true 75 | */ 76 | private static boolean setStatusBarModeForMIUI(Window window, boolean darkText) { 77 | boolean result = false; 78 | if (window != null) { 79 | Class clazz = window.getClass(); 80 | try { 81 | int darkModeFlag = 0; 82 | Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams"); 83 | Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE"); 84 | darkModeFlag = field.getInt(layoutParams); 85 | Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class); 86 | if (darkText) { 87 | extraFlagField.invoke(window, darkModeFlag, darkModeFlag);//状态栏透明且黑色字体 88 | } else { 89 | extraFlagField.invoke(window, 0, darkModeFlag);//清除黑色字体 90 | } 91 | result = true; 92 | } catch (Exception e) { 93 | 94 | } 95 | } 96 | return result; 97 | } 98 | 99 | /** 100 | * 设置状态栏图标为深色和魅族特定的文字风格 101 | * 可以用来判断是否为Flyme用户 102 | * 103 | * @param window 需要设置的窗口 104 | * @param darkText 是否把状态栏字体及图标颜色设置为深色 105 | * @return boolean 成功执行返回true 106 | */ 107 | private static boolean setStatusBarModeForFlyMe(Window window, boolean darkText) { 108 | boolean result = false; 109 | if (window != null) { 110 | try { 111 | WindowManager.LayoutParams lp = window.getAttributes(); 112 | Field darkFlag = WindowManager.LayoutParams.class 113 | .getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON"); 114 | Field meizuFlags = WindowManager.LayoutParams.class 115 | .getDeclaredField("meizuFlags"); 116 | darkFlag.setAccessible(true); 117 | meizuFlags.setAccessible(true); 118 | int bit = darkFlag.getInt(null); 119 | int value = meizuFlags.getInt(lp); 120 | if (darkText) { 121 | value |= bit; 122 | } else { 123 | value &= ~bit; 124 | } 125 | meizuFlags.setInt(lp, value); 126 | window.setAttributes(lp); 127 | result = true; 128 | } catch (Exception e) { 129 | 130 | } 131 | } 132 | return result; 133 | } 134 | 135 | /** 136 | * 设置原生Android 6.0以上系统状态栏 137 | * 138 | * @param window 139 | * @param darkText 是否把状态栏字体及图标颜色设置为深色 140 | * @return 141 | */ 142 | private static boolean setStatusBarModeForAndroidM(Window window, boolean darkText) { 143 | boolean result = false; 144 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 145 | window.getDecorView().setSystemUiVisibility(darkText ? View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | 0x00002000 : View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_VISIBLE); 146 | result = true; 147 | } 148 | return result; 149 | } 150 | 151 | 152 | /** 153 | * 判断系统是否支持状态栏文字及图标颜色变化 154 | * 155 | * @return 156 | */ 157 | public static boolean isSupportStatusBarFontChange() { 158 | if (RomUtil.getMIUIVersionCode() >= 6 || RomUtil.getFlymeVersionCode() >= 4 159 | || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)) { 160 | return true; 161 | } else 162 | return false; 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /library/src/main/java/com/aries/ui/view/title/TitleBarView.java: -------------------------------------------------------------------------------- 1 | package com.aries.ui.view.title; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.content.res.ColorStateList; 6 | import android.content.res.Resources; 7 | import android.content.res.TypedArray; 8 | import android.graphics.Color; 9 | import android.graphics.drawable.Drawable; 10 | import android.os.Build; 11 | import android.text.TextUtils; 12 | import android.util.AttributeSet; 13 | import android.util.TypedValue; 14 | import android.view.Gravity; 15 | import android.view.View; 16 | import android.view.ViewGroup; 17 | import android.view.Window; 18 | import android.view.WindowManager; 19 | import android.widget.ImageView; 20 | import android.widget.LinearLayout; 21 | import android.widget.TextView; 22 | 23 | import com.aries.ui.util.KeyboardUtil; 24 | import com.aries.ui.util.StatusBarUtil; 25 | 26 | 27 | /** 28 | * Created: AriesHoo on 2017-02-09 09:42 29 | * Function:定制标题栏 30 | * Desc: 31 | */ 32 | public class TitleBarView extends ViewGroup { 33 | 34 | public static final int DEFAULT_STATUS_BAR_ALPHA = 102;//默认透明度--5.0以上优化半透明状态栏一致 35 | private static final int DEFAULT_TEXT_COLOR = Color.WHITE;//默认文本颜色 36 | private static final int DEFAULT_TEXT_BG_COLOR = Color.TRANSPARENT;//默认子View背景色 37 | private static final int DEFAULT_MAIN_TEXT_SIZE = 18;//主标题size dp 38 | private static final int DEFAULT_TEXT_SIZE = 14;//文本默认size dp 39 | private static final int DEFAULT_SUB_TEXT_SIZE = 12;//副标题默认size dp 40 | 41 | private int mStatusBarHeight;//状态栏高度 42 | private int mScreenWidth;//屏幕高度 43 | private int systemUiVisibility;//Activity systemUiVisibility属性 44 | 45 | private Context mContext; 46 | /** 47 | * 自定义View 48 | */ 49 | private View mStatusView;//状态栏View-用于单独设置颜色 50 | private LinearLayout mLeftLayout;//左边容器 51 | private LinearLayout mCenterLayout;//中间容器 52 | private LinearLayout mRightLayout;//右边容器 53 | private TextView mLeftTv;//左边TextView 54 | private TextView mTitleMain;//主标题 55 | private TextView mTitleSub;//副标题 56 | private TextView mRightTv;//右边TextView 57 | private View mDividerView;//下方下划线 58 | 59 | 60 | /** 61 | * xml属性 62 | */ 63 | private boolean mImmersible = false; 64 | private int mOutPadding; 65 | private int mActionPadding; 66 | private boolean mCenterGravityLeft = false;//中间部分是否左对齐--默认居中 67 | private boolean mStatusBarLightMode = false;//是否浅色状态栏(黑色文字及图标) 68 | private int mStatusBarModeType = StatusBarUtil.STATUS_BAR_TYPE_DEFAULT;//设置状态栏浅色或深色模式类型标记;>0则表示支持模式切换 69 | 70 | private int mStatusColor; 71 | private int mStatusResource; 72 | private int mDividerColor; 73 | private int mDividerResource; 74 | private int mDividerHeight; 75 | private boolean mDividerVisible; 76 | 77 | private int mLeftTextSize; 78 | private int mLeftTextColor; 79 | private int mLeftTextBackgroundColor; 80 | private int mLeftDrawable; 81 | private int mLeftTextDrawableWidth; 82 | private int mLeftTextDrawableHeight; 83 | private int mLeftDrawablePadding; 84 | private int mLeftTextBackgroundResource; 85 | 86 | private int mTitleMainTextSize; 87 | private int mTitleMainTextColor; 88 | private int mTitleMainTextBackgroundColor; 89 | private int mTitleMainTextBackgroundResource; 90 | private boolean mTitleMainTextFakeBold; 91 | private boolean mTitleMainTextMarquee;//主标题是否跑马灯效果 92 | 93 | private int mTitleSubTextSize; 94 | private int mTitleSubTextColor; 95 | private int mTitleSubTextBackgroundColor; 96 | private int mTitleSubTextBackgroundResource; 97 | private boolean mTitleSubTextFakeBold; 98 | private boolean mTitleSubTextMarquee;//副标题是否跑马灯效果 99 | 100 | private int mRightTextSize; 101 | private int mRightTextColor; 102 | private int mRightTextBackgroundColor; 103 | private int mRightDrawable; 104 | private int mRightTextDrawableWidth; 105 | private int mRightTextDrawableHeight; 106 | private int mRightDrawablePadding; 107 | private int mRightTextBackgroundResource; 108 | 109 | private int mActionTextSize; 110 | private int mActionTextColor; 111 | private int mActionTextBackgroundColor; 112 | private int mActionTextBackgroundResource; 113 | 114 | private CharSequence mTitleMainText; 115 | private CharSequence mTitleSubText; 116 | private CharSequence mLeftText; 117 | private CharSequence mRightText; 118 | 119 | public TitleBarView(Context context) { 120 | this(context, null, 0); 121 | } 122 | 123 | public TitleBarView(Context context, AttributeSet attrs) { 124 | this(context, attrs, 0); 125 | } 126 | 127 | public TitleBarView(Context context, AttributeSet attrs, int defStyleAttr) { 128 | super(context, attrs, defStyleAttr); 129 | this.mContext = context; 130 | initAttributes(context, attrs); 131 | initView(context); 132 | setViewAttributes(context); 133 | } 134 | 135 | private void initAttributes(Context context, AttributeSet attrs) { 136 | TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.TitleBarView); 137 | mImmersible = ta.getBoolean(R.styleable.TitleBarView_title_immersible, true); 138 | mOutPadding = ta.getDimensionPixelSize(R.styleable.TitleBarView_title_outPadding, dip2px(12)); 139 | mActionPadding = ta.getDimensionPixelSize(R.styleable.TitleBarView_title_actionPadding, dip2px(1)); 140 | mCenterGravityLeft = ta.getBoolean(R.styleable.TitleBarView_title_centerGravityLeft, false); 141 | mStatusBarLightMode = ta.getBoolean(R.styleable.TitleBarView_title_statusBarLightMode, false); 142 | 143 | mStatusColor = ta.getColor(R.styleable.TitleBarView_title_statusColor, -1); 144 | mStatusResource = ta.getResourceId(R.styleable.TitleBarView_title_statusResource, -1); 145 | mDividerColor = ta.getColor(R.styleable.TitleBarView_title_dividerColor, Color.TRANSPARENT); 146 | mDividerResource = ta.getResourceId(R.styleable.TitleBarView_title_dividerResource, -1); 147 | mDividerHeight = ta.getDimensionPixelSize(R.styleable.TitleBarView_title_dividerHeight, dip2px(0.5f)); 148 | mDividerVisible = ta.getBoolean(R.styleable.TitleBarView_title_dividerVisible, true); 149 | 150 | mLeftText = ta.getString(R.styleable.TitleBarView_title_leftText); 151 | mLeftTextSize = ta.getDimensionPixelSize(R.styleable.TitleBarView_title_leftTextSize, dip2px(DEFAULT_TEXT_SIZE)); 152 | mLeftTextColor = ta.getColor(R.styleable.TitleBarView_title_leftTextColor, DEFAULT_TEXT_COLOR); 153 | mLeftTextBackgroundColor = ta.getColor(R.styleable.TitleBarView_title_leftTextBackgroundColor, DEFAULT_TEXT_BG_COLOR); 154 | mLeftTextBackgroundResource = ta.getResourceId(R.styleable.TitleBarView_title_leftTextBackgroundResource, -1); 155 | mLeftDrawable = ta.getResourceId(R.styleable.TitleBarView_title_leftTextDrawable, -1); 156 | mLeftTextDrawableWidth = ta.getDimensionPixelSize(R.styleable.TitleBarView_title_leftTextDrawableWidth, -1); 157 | mLeftTextDrawableHeight = ta.getDimensionPixelSize(R.styleable.TitleBarView_title_leftTextDrawableHeight, -1); 158 | mLeftDrawablePadding = ta.getDimensionPixelSize(R.styleable.TitleBarView_title_leftTextDrawablePadding, dip2px(1)); 159 | 160 | mTitleMainText = ta.getString(R.styleable.TitleBarView_title_titleMainText); 161 | mTitleMainTextSize = ta.getDimensionPixelSize(R.styleable.TitleBarView_title_titleMainTextSize, dip2px(DEFAULT_MAIN_TEXT_SIZE)); 162 | mTitleMainTextColor = ta.getColor(R.styleable.TitleBarView_title_titleMainTextColor, DEFAULT_TEXT_COLOR); 163 | mTitleMainTextBackgroundColor = ta.getColor(R.styleable.TitleBarView_title_titleMainTextBackgroundColor, DEFAULT_TEXT_BG_COLOR); 164 | mTitleMainTextBackgroundResource = ta.getResourceId(R.styleable.TitleBarView_title_titleMainTextBackgroundResource, -1); 165 | mTitleMainTextFakeBold = ta.getBoolean(R.styleable.TitleBarView_title_titleMainTextFakeBold, false); 166 | mTitleMainTextMarquee = ta.getBoolean(R.styleable.TitleBarView_title_titleMainTextMarquee, false); 167 | 168 | mTitleSubText = ta.getString(R.styleable.TitleBarView_title_titleSubText); 169 | mTitleSubTextSize = ta.getDimensionPixelSize(R.styleable.TitleBarView_title_titleSubTextSize, dip2px(DEFAULT_SUB_TEXT_SIZE)); 170 | mTitleSubTextColor = ta.getColor(R.styleable.TitleBarView_title_titleSubTextColor, DEFAULT_TEXT_COLOR); 171 | mTitleSubTextBackgroundColor = ta.getColor(R.styleable.TitleBarView_title_titleSubTextBackgroundColor, DEFAULT_TEXT_BG_COLOR); 172 | mTitleSubTextBackgroundResource = ta.getResourceId(R.styleable.TitleBarView_title_titleSubTextBackgroundResource, -1); 173 | mTitleSubTextFakeBold = ta.getBoolean(R.styleable.TitleBarView_title_titleSubTextFakeBold, false); 174 | mTitleSubTextMarquee = ta.getBoolean(R.styleable.TitleBarView_title_titleSubTextMarquee, false); 175 | 176 | mRightText = ta.getString(R.styleable.TitleBarView_title_rightText); 177 | mRightTextSize = ta.getDimensionPixelSize(R.styleable.TitleBarView_title_rightTextSize, dip2px(DEFAULT_TEXT_SIZE)); 178 | mRightTextColor = ta.getColor(R.styleable.TitleBarView_title_rightTextColor, DEFAULT_TEXT_COLOR); 179 | mRightTextBackgroundResource = ta.getResourceId(R.styleable.TitleBarView_title_rightTextBackgroundResource, -1); 180 | mRightTextBackgroundColor = ta.getColor(R.styleable.TitleBarView_title_rightTextBackgroundColor, DEFAULT_TEXT_BG_COLOR); 181 | mRightDrawable = ta.getResourceId(R.styleable.TitleBarView_title_rightTextDrawable, -1); 182 | mRightTextDrawableWidth = ta.getDimensionPixelSize(R.styleable.TitleBarView_title_rightTextDrawableWidth, -1); 183 | mRightTextDrawableHeight = ta.getDimensionPixelSize(R.styleable.TitleBarView_title_rightTextDrawableHeight, -1); 184 | mRightDrawablePadding = ta.getDimensionPixelSize(R.styleable.TitleBarView_title_rightTextDrawablePadding, dip2px(1)); 185 | 186 | mActionTextSize = ta.getDimensionPixelSize(R.styleable.TitleBarView_title_actionTextSize, dip2px(DEFAULT_TEXT_SIZE)); 187 | mActionTextColor = ta.getColor(R.styleable.TitleBarView_title_actionTextColor, DEFAULT_TEXT_COLOR); 188 | mActionTextBackgroundColor = ta.getColor(R.styleable.TitleBarView_title_actionTextBackgroundColor, DEFAULT_TEXT_BG_COLOR); 189 | mActionTextBackgroundResource = ta.getResourceId(R.styleable.TitleBarView_title_actionTextBackgroundResource, -1); 190 | ta.recycle();//回收 191 | } 192 | 193 | /** 194 | * 初始化子View 195 | * 196 | * @param context 197 | */ 198 | private void initView(Context context) { 199 | LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); 200 | LayoutParams dividerParams = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, mDividerHeight); 201 | 202 | mLeftLayout = new LinearLayout(context); 203 | mCenterLayout = new LinearLayout(context); 204 | mRightLayout = new LinearLayout(context); 205 | mStatusView = new View(context); 206 | mDividerView = new View(context); 207 | 208 | mLeftLayout.setGravity(Gravity.CENTER_VERTICAL); 209 | mCenterLayout.setOrientation(LinearLayout.VERTICAL); 210 | mRightLayout.setGravity(Gravity.CENTER_VERTICAL); 211 | 212 | mLeftTv = new TextView(context); 213 | mLeftTv.setGravity(Gravity.CENTER); 214 | mLeftTv.setLines(1); 215 | 216 | mTitleMain = new TextView(context); 217 | mTitleSub = new TextView(context); 218 | 219 | mRightTv = new TextView(context); 220 | mRightTv.setGravity(Gravity.CENTER); 221 | mRightTv.setLines(1); 222 | 223 | mLeftLayout.addView(mLeftTv, params); 224 | mRightLayout.addView(mRightTv, params); 225 | addView(mLeftLayout, params);//添加左边容器 226 | addView(mCenterLayout, params);//添加中间容器 227 | addView(mRightLayout, params);//添加右边容器 228 | addView(mDividerView, dividerParams);//添加下划线View 229 | addView(mStatusView);//添加状态栏View 230 | } 231 | 232 | /** 233 | * 设置xml默认属性 234 | * 235 | * @param context 236 | */ 237 | private void setViewAttributes(final Context context) { 238 | mScreenWidth = getScreenWidth(); 239 | mStatusBarHeight = getStatusBarHeight(); 240 | if (context instanceof Activity) { 241 | setImmersible((Activity) context, mImmersible); 242 | if (mStatusBarLightMode) 243 | setStatusBarLightMode(mStatusBarLightMode); 244 | } 245 | setOutPadding(mOutPadding); 246 | setActionPadding(mActionPadding); 247 | setCenterGravityLeft(mCenterGravityLeft); 248 | setStatusColor(mStatusColor); 249 | setStatusResource(mStatusResource); 250 | setDividerColor(mDividerColor); 251 | setDividerResource(mDividerResource); 252 | setDividerHeight(mDividerHeight); 253 | setDividerVisible(mDividerVisible); 254 | setLeftText(mLeftText); 255 | setLeftTextSize(TypedValue.COMPLEX_UNIT_PX, mLeftTextSize); 256 | setLeftTextColor(mLeftTextColor); 257 | setLeftTextBackgroundColor(mLeftTextBackgroundColor); 258 | setLeftTextBackgroundResource(mLeftTextBackgroundResource); 259 | setLeftTextDrawable(mLeftDrawable); 260 | setLeftTextDrawableWidth(mLeftTextDrawableWidth); 261 | setLeftTextDrawableHeight(mLeftTextDrawableHeight); 262 | setTitleMainText(mTitleMainText); 263 | setTitleMainTextSize(TypedValue.COMPLEX_UNIT_PX, mTitleMainTextSize); 264 | setTitleMainTextColor(mTitleMainTextColor); 265 | setTitleMainTextBackgroundColor(mTitleMainTextBackgroundColor); 266 | setTitleMainTextBackgroundResource(mTitleMainTextBackgroundResource); 267 | setTitleMainTextFakeBold(mTitleMainTextFakeBold); 268 | setTitleMainTextMarquee(mTitleMainTextMarquee); 269 | setTitleSubText(mTitleSubText); 270 | setTitleSubTextSize(TypedValue.COMPLEX_UNIT_PX, mTitleSubTextSize); 271 | setTitleSubTextColor(mTitleSubTextColor); 272 | setTitleSubTextBackgroundColor(mTitleSubTextBackgroundColor); 273 | setTitleSubTextBackgroundResource(mTitleSubTextBackgroundResource); 274 | setTitleSubTextFakeBold(mTitleSubTextFakeBold); 275 | setTitleSubTextMarquee(mTitleSubTextMarquee); 276 | setRightText(mRightText); 277 | setRightTextSize(TypedValue.COMPLEX_UNIT_PX, mRightTextSize); 278 | setRightTextColor(mRightTextColor); 279 | setRightTextBackgroundColor(mRightTextBackgroundColor); 280 | setRightTextBackgroundResource(mRightTextBackgroundResource); 281 | setRightTextDrawable(mRightDrawable); 282 | setRightTextDrawableWidth(mRightTextDrawableWidth); 283 | setRightTextDrawableHeight(mRightTextDrawableHeight); 284 | } 285 | 286 | /** 287 | * 根据位置获取 LinearLayout 288 | * 289 | * @param gravity 参考{@link Gravity} 290 | * @return 291 | */ 292 | public LinearLayout getLinearLayout(int gravity) { 293 | if (gravity == Gravity.LEFT || gravity == Gravity.START) { 294 | return mLeftLayout; 295 | } else if (gravity == Gravity.CENTER) { 296 | return mCenterLayout; 297 | } else if (gravity == Gravity.END || gravity == Gravity.RIGHT) { 298 | return mRightLayout; 299 | } 300 | return mCenterLayout; 301 | } 302 | 303 | /** 304 | * 根据位置获取TextView 305 | * 306 | * @param gravity 参考{@link Gravity} 307 | * @return 308 | */ 309 | public TextView getTextView(int gravity) { 310 | if (gravity == Gravity.LEFT || gravity == Gravity.START) { 311 | return mLeftTv; 312 | } else if (gravity == (Gravity.CENTER | Gravity.TOP)) { 313 | return mTitleMain; 314 | } else if (gravity == (Gravity.CENTER | Gravity.BOTTOM)) { 315 | return mTitleSub; 316 | } else if (gravity == Gravity.END || gravity == Gravity.RIGHT) { 317 | return mRightTv; 318 | } 319 | return mTitleMain; 320 | } 321 | 322 | /** 323 | * 根据位置获取View 324 | * 325 | * @param gravity 参考{@link Gravity} 326 | * @return 327 | */ 328 | public View getView(int gravity) { 329 | if (gravity == Gravity.TOP) { 330 | return mStatusView; 331 | } else if (gravity == Gravity.BOTTOM) { 332 | return mDividerView; 333 | } 334 | return mStatusView; 335 | } 336 | 337 | /** 338 | * 获取设置状态栏文字图标样式模式 339 | * 340 | * @return >0则表示设置成功 参考{@link StatusBarUtil} 341 | */ 342 | public int getStatusBarModeType() { 343 | return mStatusBarModeType; 344 | } 345 | 346 | public TitleBarView setImmersible(Activity activity, boolean immersible) { 347 | return setImmersible(activity, immersible, true); 348 | } 349 | 350 | public TitleBarView setImmersible(Activity activity, boolean immersible, boolean isTransStatusBar) { 351 | return setImmersible(activity, immersible, isTransStatusBar, true); 352 | } 353 | 354 | /** 355 | * 设置沉浸式状态栏,4.4以上系统支持 356 | * 357 | * @param activity 358 | * @param immersible 359 | * @param isTransStatusBar 是否透明状态栏 360 | * @param isPlusStatusBar 是否增加状态栏高度--用于控制底部有输入框 (设置false/xml背景色必须保持和状态栏一致) 361 | */ 362 | public TitleBarView setImmersible(Activity activity, boolean immersible, boolean isTransStatusBar, boolean isPlusStatusBar) { 363 | this.mImmersible = immersible; 364 | if (isPlusStatusBar && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 365 | mStatusBarHeight = getStatusBarHeight(); 366 | } else { 367 | mStatusBarHeight = 0; 368 | } 369 | if (activity == null) { 370 | return this; 371 | } 372 | //透明状态栏 373 | Window window = activity.getWindow(); 374 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 375 | mStatusView.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, mStatusBarHeight)); 376 | // 透明状态栏 377 | window.addFlags( 378 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 379 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 380 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 381 | systemUiVisibility = window.getDecorView().getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; 382 | window.getDecorView().setSystemUiVisibility(systemUiVisibility); 383 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); 384 | window.setStatusBarColor(Color.TRANSPARENT); 385 | } 386 | } 387 | setStatusAlpha(immersible ? isTransStatusBar ? 0 : 102 : 255); 388 | return this; 389 | } 390 | 391 | @Override 392 | protected void onLayout(boolean changed, int l, int t, int r, int b) { 393 | int left = mLeftLayout.getMeasuredWidth(); 394 | int right = mRightLayout.getMeasuredWidth(); 395 | int center = mCenterLayout.getMeasuredWidth(); 396 | mLeftLayout.layout(0, mStatusBarHeight, left, mLeftLayout.getMeasuredHeight() + mStatusBarHeight); 397 | mRightLayout.layout(mScreenWidth - right, mStatusBarHeight, mScreenWidth, mRightLayout.getMeasuredHeight() + mStatusBarHeight); 398 | boolean isMuchScreen = left + right + center >= mScreenWidth; 399 | if (left > right) { 400 | mCenterLayout.layout(left, mStatusBarHeight, isMuchScreen ? mScreenWidth - right : mScreenWidth - left, getMeasuredHeight() - mDividerHeight); 401 | } else { 402 | mCenterLayout.layout(isMuchScreen ? left : right, mStatusBarHeight, mScreenWidth - right, getMeasuredHeight() - mDividerHeight); 403 | } 404 | mDividerView.layout(0, getMeasuredHeight() - mDividerView.getMeasuredHeight(), getMeasuredWidth(), getMeasuredHeight()); 405 | mStatusView.layout(0, 0, getMeasuredWidth(), mStatusBarHeight); 406 | } 407 | 408 | @Override 409 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 410 | measureChild(mLeftLayout, widthMeasureSpec, heightMeasureSpec); 411 | measureChild(mRightLayout, widthMeasureSpec, heightMeasureSpec); 412 | measureChild(mCenterLayout, widthMeasureSpec, heightMeasureSpec); 413 | measureChild(mDividerView, widthMeasureSpec, heightMeasureSpec); 414 | measureChild(mStatusView, widthMeasureSpec, heightMeasureSpec); 415 | int left = mLeftLayout.getMeasuredWidth(); 416 | int right = mRightLayout.getMeasuredWidth(); 417 | int center = mCenterLayout.getMeasuredWidth(); 418 | //判断左、中、右实际占用宽度是否等于或者超过屏幕宽度 419 | boolean isMuchScreen = left + right + center >= mScreenWidth; 420 | if (!mCenterGravityLeft) {//不设置中间布局左对齐才进行中间布局重新测量 421 | if (isMuchScreen) { 422 | center = mScreenWidth - left - right; 423 | } else { 424 | if (left > right) { 425 | center = mScreenWidth - 2 * left; 426 | } else { 427 | center = mScreenWidth - 2 * right; 428 | } 429 | } 430 | mCenterLayout.measure(MeasureSpec.makeMeasureSpec(center, MeasureSpec.EXACTLY), heightMeasureSpec); 431 | } 432 | //重新测量宽高--增加状态栏及下划线的高度 433 | setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec) + mStatusBarHeight + mDividerHeight); 434 | } 435 | 436 | public TitleBarView setOutPadding(int paddingValue) { 437 | mOutPadding = paddingValue; 438 | mLeftLayout.setPadding(mOutPadding, 0, 0, 0); 439 | mRightLayout.setPadding(0, 0, mOutPadding, 0); 440 | return this; 441 | } 442 | 443 | public TitleBarView setCenterGravityLeft(boolean enable) { 444 | this.mCenterGravityLeft = enable; 445 | mTitleMain.setGravity(mCenterGravityLeft ? Gravity.LEFT : Gravity.CENTER); 446 | mCenterLayout.setGravity(mCenterGravityLeft ? Gravity.LEFT | Gravity.CENTER_VERTICAL : Gravity.CENTER); 447 | mTitleSub.setGravity(mCenterGravityLeft ? Gravity.LEFT : Gravity.CENTER); 448 | return this; 449 | } 450 | 451 | public boolean setStatusBarLightMode(boolean mStatusBarLightMode) { 452 | if (mContext instanceof Activity) { 453 | return setStatusBarLightMode((Activity) mContext, mStatusBarLightMode); 454 | } 455 | return false; 456 | } 457 | 458 | public boolean setStatusBarLightMode(Activity mActivity, boolean mStatusBarLightMode) { 459 | boolean result = false; 460 | this.mStatusBarLightMode = mStatusBarLightMode; 461 | if (mActivity != null) { 462 | if (mStatusBarLightMode) { 463 | mStatusBarModeType = StatusBarUtil.setStatusBarLightMode(mActivity); 464 | result = mStatusBarModeType > 0; 465 | } else { 466 | mStatusBarModeType = StatusBarUtil.setStatusBarDarkMode(mActivity); 467 | result = mStatusBarModeType > 0; 468 | } 469 | } 470 | return result; 471 | } 472 | 473 | public TitleBarView setActionPadding(int actionPadding) { 474 | mActionPadding = actionPadding; 475 | return this; 476 | } 477 | 478 | /** 479 | * 设置状态栏颜色 480 | * 481 | * @param color 482 | */ 483 | public TitleBarView setStatusColor(int color) { 484 | try { 485 | mStatusColor = color; 486 | mStatusView.setBackgroundColor(color); 487 | } catch (Exception e) { 488 | 489 | } 490 | return this; 491 | } 492 | 493 | /** 494 | * 透明度 0-255 495 | * 496 | * @param statusBarAlpha 497 | */ 498 | public TitleBarView setStatusAlpha(int statusBarAlpha) { 499 | if (statusBarAlpha < 0) { 500 | statusBarAlpha = 0; 501 | } else if (statusBarAlpha > 255) { 502 | statusBarAlpha = 255; 503 | } 504 | return setStatusColor(Color.argb(statusBarAlpha, 0, 0, 0)); 505 | } 506 | 507 | public TitleBarView setStatusResource(int resource) { 508 | try { 509 | mStatusResource = resource; 510 | mStatusView.setBackgroundResource(resource); 511 | } catch (Exception e) { 512 | 513 | } 514 | return this; 515 | } 516 | 517 | public TitleBarView setDividerColor(int color) { 518 | mDividerColor = color; 519 | mDividerView.setBackgroundColor(color); 520 | return this; 521 | } 522 | 523 | public TitleBarView setDividerResource(int resource) { 524 | mDividerResource = resource; 525 | if (mDividerResource != -1) 526 | mDividerView.setBackgroundResource(resource); 527 | return this; 528 | } 529 | 530 | public TitleBarView setDividerHeight(int dividerHeight) { 531 | mDividerHeight = dividerHeight; 532 | mDividerView.getLayoutParams().height = dividerHeight; 533 | return this; 534 | } 535 | 536 | public TitleBarView setDividerVisible(boolean visible) { 537 | mDividerVisible = visible; 538 | mDividerView.setVisibility(visible ? VISIBLE : GONE); 539 | return this; 540 | } 541 | 542 | public TitleBarView setLeftText(CharSequence title) { 543 | mLeftText = title; 544 | mLeftTv.setText(title); 545 | return this; 546 | } 547 | 548 | public TitleBarView setLeftText(int id) { 549 | return setLeftText(getResources().getString(id)); 550 | } 551 | 552 | /** 553 | * 设置文字大小 554 | * 555 | * @param unit 文字单位{@link TypedValue} 556 | * @param size 557 | * @return 558 | */ 559 | public TitleBarView setLeftTextSize(int unit, float size) { 560 | mLeftTv.setTextSize(unit, size); 561 | return this; 562 | } 563 | 564 | public TitleBarView setLeftTextSize(float size) { 565 | return setLeftTextSize(TypedValue.COMPLEX_UNIT_SP, size); 566 | } 567 | 568 | public TitleBarView setLeftTextColor(int color) { 569 | mLeftTv.setTextColor(color); 570 | return this; 571 | } 572 | 573 | /** 574 | * 设置文字状态颜色-如按下颜色变化 575 | * 576 | * @param color 577 | * @return 578 | */ 579 | public TitleBarView setLeftTextColor(ColorStateList color) { 580 | try { 581 | mLeftTv.setTextColor(color); 582 | } catch (Exception e) { 583 | } 584 | return this; 585 | } 586 | 587 | public TitleBarView setLeftTextBackgroundColor(int color) { 588 | mLeftTv.setBackgroundColor(color); 589 | return this; 590 | } 591 | 592 | /** 593 | * @param resId 594 | */ 595 | public TitleBarView setLeftTextBackgroundResource(int resId) { 596 | try { 597 | mLeftTextBackgroundResource = resId; 598 | mLeftTv.setBackgroundResource(mLeftTextBackgroundResource); 599 | } catch (Exception e) { 600 | 601 | } 602 | return this; 603 | } 604 | 605 | /** 606 | * 左边文本添加图片 607 | * 608 | * @param id 资源id 609 | */ 610 | public TitleBarView setLeftTextDrawable(int id, int drawablePadding) { 611 | Drawable mDrawable = null; 612 | try { 613 | mDrawable = getResources().getDrawable(id); 614 | if (mDrawable != null) { 615 | mDrawable.setBounds(0, 0, 616 | mLeftTextDrawableWidth != -1 ? mLeftTextDrawableWidth : mDrawable.getIntrinsicWidth(), 617 | mLeftTextDrawableHeight != -1 ? mLeftTextDrawableHeight : mDrawable.getIntrinsicHeight()); 618 | } 619 | } catch (Exception e) { 620 | } 621 | mLeftTv.setCompoundDrawables(mDrawable, null, null, null); 622 | return setLeftTextDrawablePadding(drawablePadding); 623 | } 624 | 625 | public TitleBarView setLeftTextDrawable(int id) { 626 | mLeftDrawable = id; 627 | return setLeftTextDrawable(id, mLeftDrawablePadding); 628 | } 629 | 630 | public TitleBarView setLeftTextDrawableWidth(int width) { 631 | mLeftTextDrawableWidth = width; 632 | return setLeftTextDrawable(mLeftDrawable); 633 | } 634 | 635 | public TitleBarView setLeftTextDrawableHeight(int height) { 636 | mLeftTextDrawableHeight = height; 637 | return setLeftTextDrawable(mLeftDrawable); 638 | } 639 | 640 | public TitleBarView setLeftTextDrawablePadding(int drawablePadding) { 641 | this.mLeftDrawablePadding = drawablePadding; 642 | mLeftTv.setCompoundDrawablePadding(mLeftDrawablePadding); 643 | return this; 644 | } 645 | 646 | public TitleBarView setLeftTextDrawablePadding(float drawablePadding) { 647 | return setLeftTextDrawablePadding(dip2px(drawablePadding)); 648 | } 649 | 650 | public TitleBarView setLeftTextPadding(int left, int top, int right, int bottom) { 651 | mLeftTv.setPadding(left, top, right, bottom); 652 | return this; 653 | } 654 | 655 | public TitleBarView setOnLeftTextClickListener(OnClickListener l) { 656 | mLeftTv.setOnClickListener(l); 657 | return this; 658 | } 659 | 660 | public TitleBarView setLeftVisible(boolean visible) { 661 | mLeftTv.setVisibility(visible ? View.VISIBLE : View.GONE); 662 | return this; 663 | } 664 | 665 | public TitleBarView setTitleMainText(int id) { 666 | return setTitleMainText(getResources().getString(id)); 667 | } 668 | 669 | public TitleBarView setTitleMainText(CharSequence charSequence) { 670 | mTitleMain.setText(charSequence); 671 | if (!TextUtils.isEmpty(charSequence) && !hasChildView(mCenterLayout, mTitleMain)) {//非空且还未添加主标题 672 | mCenterLayout.addView(mTitleMain, 0); 673 | } 674 | return this; 675 | } 676 | 677 | public TitleBarView setTitleMainTextSize(int unit, float titleMainTextSpValue) { 678 | mTitleMain.setTextSize(unit, titleMainTextSpValue); 679 | return this; 680 | } 681 | 682 | /** 683 | * 设置文字大小 参考{@link TypedValue} 684 | * 685 | * @param titleMainTextSpValue 686 | * @return 687 | */ 688 | public TitleBarView setTitleMainTextSize(float titleMainTextSpValue) { 689 | return setTitleMainTextSize(TypedValue.COMPLEX_UNIT_SP, titleMainTextSpValue); 690 | } 691 | 692 | public TitleBarView setTitleMainTextColor(int color) { 693 | mTitleMain.setTextColor(color); 694 | return this; 695 | } 696 | 697 | public TitleBarView setTitleMainTextBackgroundColor(int color) { 698 | try { 699 | mTitleMainTextBackgroundColor = color; 700 | mTitleMain.setBackgroundColor(color); 701 | } catch (Exception e) { 702 | 703 | } 704 | return this; 705 | } 706 | 707 | public TitleBarView setTitleMainTextBackgroundResource(int resId) { 708 | try { 709 | mTitleMainTextBackgroundResource = resId; 710 | mTitleMain.setBackgroundResource(resId); 711 | } catch (Exception e) { 712 | 713 | } 714 | return this; 715 | } 716 | 717 | /** 718 | * 设置粗体标题 719 | * 720 | * @param isFakeBold 721 | */ 722 | public TitleBarView setTitleMainTextFakeBold(boolean isFakeBold) { 723 | this.mTitleMainTextFakeBold = isFakeBold; 724 | mTitleMain.getPaint().setFakeBoldText(mTitleMainTextFakeBold); 725 | return this; 726 | } 727 | 728 | public TitleBarView setTitleMainTextMarquee(boolean enable) { 729 | this.mTitleMainTextMarquee = enable; 730 | if (enable) { 731 | setTitleSubTextMarquee(false); 732 | mTitleMain.setSingleLine(); 733 | mTitleMain.setEllipsize(TextUtils.TruncateAt.MARQUEE); 734 | mTitleMain.setFocusable(true); 735 | mTitleMain.setFocusableInTouchMode(true); 736 | mTitleMain.requestFocus(); 737 | mTitleMain.setOnFocusChangeListener(new View.OnFocusChangeListener() { 738 | @Override 739 | public void onFocusChange(View v, boolean hasFocus) { 740 | if (!hasFocus && mTitleMainTextMarquee) { 741 | mTitleMain.requestFocus(); 742 | } 743 | } 744 | }); 745 | //开启硬件加速 746 | mTitleMain.setLayerType(View.LAYER_TYPE_HARDWARE, null); 747 | } else { 748 | mTitleMain.setMaxLines(2); 749 | mTitleMain.setEllipsize(TextUtils.TruncateAt.END); 750 | mTitleMain.setOnFocusChangeListener(null); 751 | //关闭硬件加速 752 | mTitleMain.setLayerType(View.LAYER_TYPE_NONE, null); 753 | } 754 | return this; 755 | } 756 | 757 | public TitleBarView setTitleMainTextPadding(int left, int top, int right, int bottom) { 758 | mTitleMain.setPadding(left, top, right, bottom); 759 | return this; 760 | } 761 | 762 | public TitleBarView setTitleSubText(CharSequence charSequence) { 763 | if (charSequence == null || charSequence.toString().isEmpty()) { 764 | mTitleSub.setVisibility(GONE); 765 | } else { 766 | mTitleSub.setVisibility(VISIBLE); 767 | } 768 | mTitleSub.setText(charSequence); 769 | if (!TextUtils.isEmpty(charSequence) && !hasChildView(mCenterLayout, mTitleSub)) {//非空且还未添加副标题 770 | if (hasChildView(mCenterLayout, mTitleMain)) { 771 | mTitleMain.setSingleLine(); 772 | mTitleSub.setSingleLine(); 773 | } 774 | mCenterLayout.addView(mTitleSub); 775 | } 776 | return this; 777 | } 778 | 779 | public TitleBarView setTitleSubText(int id) { 780 | return setTitleSubText(getResources().getString(id)); 781 | } 782 | 783 | /** 784 | * 设置文字大小 785 | * 786 | * @param unit 单位 参考{@link TypedValue} 787 | * @param value 788 | * @return 789 | */ 790 | public TitleBarView setTitleSubTextSize(int unit, float value) { 791 | mTitleSub.setTextSize(unit, value); 792 | return this; 793 | } 794 | 795 | public TitleBarView setTitleSubTextSize(float spValue) { 796 | return setTitleSubTextSize(TypedValue.COMPLEX_UNIT_SP, spValue); 797 | } 798 | 799 | public TitleBarView setTitleSubTextColor(int color) { 800 | mTitleSub.setTextColor(color); 801 | return this; 802 | } 803 | 804 | public TitleBarView setTitleSubTextBackgroundColor(int color) { 805 | try { 806 | mTitleSubTextBackgroundColor = color; 807 | mTitleSub.setBackgroundColor(color); 808 | } catch (Exception e) { 809 | 810 | } 811 | return this; 812 | } 813 | 814 | public TitleBarView setTitleSubTextBackgroundResource(int resId) { 815 | try { 816 | mTitleSubTextBackgroundResource = resId; 817 | mTitleSub.setBackgroundResource(resId); 818 | } catch (Exception e) { 819 | 820 | } 821 | return this; 822 | } 823 | 824 | /** 825 | * 设置粗体标题 826 | * 827 | * @param isFakeBold 828 | */ 829 | public TitleBarView setTitleSubTextFakeBold(boolean isFakeBold) { 830 | this.mTitleSubTextFakeBold = isFakeBold; 831 | mTitleSub.getPaint().setFakeBoldText(mTitleSubTextFakeBold); 832 | return this; 833 | } 834 | 835 | /** 836 | * 设置TextView 跑马灯 837 | * 838 | * @param enable 839 | */ 840 | public TitleBarView setTitleSubTextMarquee(boolean enable) { 841 | this.mTitleSubTextMarquee = enable; 842 | if (enable) { 843 | setTitleMainTextMarquee(false); 844 | mTitleSub.setSingleLine(); 845 | mTitleSub.setEllipsize(TextUtils.TruncateAt.MARQUEE); 846 | mTitleSub.setFocusable(true); 847 | mTitleSub.setFocusableInTouchMode(true); 848 | mTitleSub.requestFocus(); 849 | mTitleSub.setOnFocusChangeListener(new View.OnFocusChangeListener() { 850 | @Override 851 | public void onFocusChange(View v, boolean hasFocus) { 852 | if (!hasFocus && mTitleSubTextMarquee) { 853 | mTitleMain.requestFocus(); 854 | } 855 | } 856 | }); 857 | //开启硬件加速 858 | mTitleSub.setLayerType(View.LAYER_TYPE_HARDWARE, null); 859 | } else { 860 | mTitleSub.setMaxLines(2); 861 | mTitleSub.setEllipsize(TextUtils.TruncateAt.END); 862 | mTitleSub.setOnFocusChangeListener(null); 863 | //关闭硬件加速 864 | mTitleSub.setLayerType(View.LAYER_TYPE_NONE, null); 865 | } 866 | return this; 867 | } 868 | 869 | public TitleBarView setOnCenterClickListener(OnClickListener l) { 870 | mCenterLayout.setOnClickListener(l); 871 | return this; 872 | } 873 | 874 | public TitleBarView setRightText(CharSequence title) { 875 | mRightTv.setText(title); 876 | return this; 877 | } 878 | 879 | public TitleBarView setRightText(int id) { 880 | return setRightText(getResources().getString(id)); 881 | } 882 | 883 | /** 884 | * 设置文字大小 885 | * 886 | * @param unit 单位 参考{@link TypedValue} 887 | * @param size 888 | * @return 889 | */ 890 | public TitleBarView setRightTextSize(int unit, float size) { 891 | mRightTv.setTextSize(unit, size); 892 | return this; 893 | } 894 | 895 | public TitleBarView setRightTextSize(float size) { 896 | return setRightTextSize(TypedValue.COMPLEX_UNIT_SP, size); 897 | } 898 | 899 | public TitleBarView setRightTextColor(int color) { 900 | mRightTv.setTextColor(color); 901 | return this; 902 | } 903 | 904 | public TitleBarView setRightTextColor(ColorStateList color) { 905 | try { 906 | mRightTv.setTextColor(color); 907 | } catch (Exception e) { 908 | } 909 | return this; 910 | } 911 | 912 | public TitleBarView setRightTextBackgroundColor(int color) { 913 | try { 914 | mRightTextBackgroundColor = color; 915 | mRightTv.setBackgroundColor(color); 916 | } catch (Exception e) { 917 | 918 | } 919 | return this; 920 | } 921 | 922 | public TitleBarView setRightTextBackgroundResource(int id) { 923 | try { 924 | mRightTextBackgroundResource = id; 925 | mRightTv.setBackgroundResource(id); 926 | } catch (Exception e) { 927 | 928 | } 929 | return this; 930 | } 931 | 932 | /** 933 | * 右边文本添加图片 934 | * 935 | * @param id 资源id 936 | */ 937 | public TitleBarView setRightTextDrawable(int id, int drawablePadding) { 938 | Drawable mDrawable = null; 939 | try { 940 | mDrawable = getResources().getDrawable(id); 941 | if (mDrawable != null) { 942 | mDrawable.setBounds(0, 0, 943 | mRightTextDrawableWidth != -1 ? mRightTextDrawableWidth : mDrawable.getIntrinsicWidth(), 944 | mRightTextDrawableHeight != -1 ? mRightTextDrawableHeight : mDrawable.getIntrinsicHeight()); 945 | } 946 | } catch (Exception e) { 947 | } 948 | mRightTv.setCompoundDrawables(null, null, mDrawable, null); 949 | return setRightTextDrawablePadding(drawablePadding); 950 | } 951 | 952 | public TitleBarView setRightTextDrawablePadding(int drawablePadding) { 953 | this.mRightDrawablePadding = drawablePadding; 954 | mRightTv.setCompoundDrawablePadding(mRightDrawablePadding); 955 | return this; 956 | } 957 | 958 | public TitleBarView setRightTextDrawablePadding(float drawablePadding) { 959 | return setRightTextDrawablePadding(dip2px(drawablePadding)); 960 | } 961 | 962 | public TitleBarView setRightTextDrawable(int id) { 963 | mRightDrawable = id; 964 | return setRightTextDrawable(id, mRightDrawablePadding); 965 | } 966 | 967 | public TitleBarView setRightTextDrawableWidth(int width) { 968 | mRightTextDrawableWidth = width; 969 | return setRightTextDrawable(mRightDrawable); 970 | } 971 | 972 | public TitleBarView setRightTextDrawableHeight(int height) { 973 | mRightTextDrawableHeight = height; 974 | return setRightTextDrawable(mRightDrawable); 975 | } 976 | 977 | public TitleBarView setRightTextPadding(int left, int top, int right, int bottom) { 978 | mRightTv.setPadding(left, top, right, bottom); 979 | return this; 980 | } 981 | 982 | public TitleBarView setOnRightTextClickListener(OnClickListener l) { 983 | mRightTv.setOnClickListener(l); 984 | return this; 985 | } 986 | 987 | public TitleBarView setRightVisible(boolean visible) { 988 | mRightTv.setVisibility(visible ? View.VISIBLE : View.GONE); 989 | return this; 990 | } 991 | 992 | public TitleBarView setActionTextSize(int mActionTextSize) { 993 | this.mActionTextSize = mActionTextSize; 994 | return this; 995 | } 996 | 997 | public TitleBarView setActionTextSize(float mActionTextSize) { 998 | setActionTextSize(dip2px(mActionTextSize)); 999 | return this; 1000 | } 1001 | 1002 | public TitleBarView setActionTextColor(int mActionTextColor) { 1003 | this.mActionTextColor = mActionTextColor; 1004 | return this; 1005 | } 1006 | 1007 | public TitleBarView setActionTextBackgroundColor(int mActionTextBackgroundColor) { 1008 | this.mActionTextBackgroundColor = mActionTextBackgroundColor; 1009 | return this; 1010 | } 1011 | 1012 | public TitleBarView setActionTextBackgroundResource(int mActionTextBackgroundResource) { 1013 | this.mActionTextBackgroundResource = mActionTextBackgroundResource; 1014 | return this; 1015 | } 1016 | 1017 | /** 1018 | * 设置底部有输入框控制方案--IM常见 1019 | */ 1020 | public TitleBarView setBottomEditTextControl(Activity mActivity) { 1021 | KeyboardUtil.with(mActivity).setEnable(); 1022 | return this; 1023 | } 1024 | 1025 | public TitleBarView setBottomEditTextControl() { 1026 | if (mContext instanceof Activity) { 1027 | setBottomEditTextControl((Activity) mContext); 1028 | } 1029 | return this; 1030 | } 1031 | 1032 | public TitleBarView addLeftAction(Action action, int position) { 1033 | View view = inflateAction(action); 1034 | mLeftLayout.addView(view, position); 1035 | return this; 1036 | } 1037 | 1038 | public TitleBarView addLeftAction(Action action) { 1039 | return addLeftAction(action, -1); 1040 | } 1041 | 1042 | /** 1043 | * 自定义中间部分布局 1044 | */ 1045 | public TitleBarView addCenterAction(Action action, int position) { 1046 | View view = inflateAction(action); 1047 | mCenterLayout.addView(view, position); 1048 | return this; 1049 | } 1050 | 1051 | /** 1052 | * 自定义中间部分布局 1053 | */ 1054 | public TitleBarView addCenterAction(Action action) { 1055 | return addCenterAction(action, -1); 1056 | } 1057 | 1058 | /** 1059 | * 在标题栏右边添加action 1060 | * 1061 | * @param action 1062 | * @param position 添加的位置 1063 | */ 1064 | public TitleBarView addRightAction(Action action, int position) { 1065 | View view = inflateAction(action); 1066 | mRightLayout.addView(view, position); 1067 | return this; 1068 | } 1069 | 1070 | public TitleBarView addRightAction(Action action) { 1071 | return addRightAction(action, -1); 1072 | } 1073 | 1074 | /** 1075 | * 通过action加载一个View 1076 | * 1077 | * @param action 1078 | * @return 1079 | */ 1080 | private View inflateAction(Action action) { 1081 | View view = null; 1082 | Object obj = action.getData(); 1083 | if (obj == null) 1084 | return null; 1085 | if (obj instanceof View) { 1086 | view = (View) obj; 1087 | } else if (obj instanceof String) { 1088 | TextView text = new TextView(getContext()); 1089 | text.setGravity(Gravity.CENTER); 1090 | text.setText((String) obj); 1091 | text.setTextSize(TypedValue.COMPLEX_UNIT_PX, mActionTextSize); 1092 | text.setTextColor(mActionTextColor); 1093 | text.setBackgroundColor(mActionTextBackgroundColor); 1094 | if (mActionTextBackgroundResource != -1) { 1095 | text.setBackgroundResource(mActionTextBackgroundResource); 1096 | } 1097 | view = text; 1098 | } else if (obj instanceof Integer) { 1099 | ImageView img = new ImageView(getContext()); 1100 | img.setScaleType(ImageView.ScaleType.CENTER_CROP); 1101 | img.setImageResource((Integer) obj); 1102 | view = img; 1103 | } 1104 | view.setPadding(mActionPadding, 0, mActionPadding, 0); 1105 | view.setTag(action); 1106 | view.setOnClickListener(action.getOnClickListener()); 1107 | return view; 1108 | } 1109 | 1110 | /** 1111 | * 添加View以及相应的动作接口 1112 | */ 1113 | public interface Action { 1114 | T getData(); 1115 | 1116 | OnClickListener getOnClickListener(); 1117 | } 1118 | 1119 | public class ImageAction implements Action { 1120 | 1121 | private int mDrawable; 1122 | private OnClickListener onClickListener; 1123 | 1124 | public ImageAction(int mDrawable, OnClickListener onClickListener) { 1125 | this.mDrawable = mDrawable; 1126 | this.onClickListener = onClickListener; 1127 | } 1128 | 1129 | public ImageAction(int mDrawable) { 1130 | this.mDrawable = mDrawable; 1131 | } 1132 | 1133 | @Override 1134 | public Integer getData() { 1135 | return mDrawable; 1136 | } 1137 | 1138 | @Override 1139 | public OnClickListener getOnClickListener() { 1140 | return onClickListener; 1141 | } 1142 | 1143 | } 1144 | 1145 | public class TextAction implements Action { 1146 | 1147 | private String mText; 1148 | private OnClickListener onClickListener; 1149 | 1150 | public TextAction(String mText, OnClickListener onClickListener) { 1151 | this.mText = mText; 1152 | this.onClickListener = onClickListener; 1153 | } 1154 | 1155 | public TextAction(String mText) { 1156 | this.mText = mText; 1157 | } 1158 | 1159 | public TextAction(int mText) { 1160 | this.mText = getResources().getString(mText); 1161 | } 1162 | 1163 | public TextAction(int mText, OnClickListener onClickListener) { 1164 | this.mText = getResources().getString(mText); 1165 | this.onClickListener = onClickListener; 1166 | } 1167 | 1168 | @Override 1169 | public String getData() { 1170 | return mText; 1171 | } 1172 | 1173 | @Override 1174 | public OnClickListener getOnClickListener() { 1175 | return onClickListener; 1176 | } 1177 | 1178 | } 1179 | 1180 | public class ViewAction implements Action { 1181 | 1182 | private View mView; 1183 | private OnClickListener onClickListener; 1184 | 1185 | public ViewAction(View mView, OnClickListener onClickListener) { 1186 | this.mView = mView; 1187 | this.onClickListener = onClickListener; 1188 | } 1189 | 1190 | public ViewAction(View mView) { 1191 | this.mView = mView; 1192 | } 1193 | 1194 | @Override 1195 | public View getData() { 1196 | return mView; 1197 | } 1198 | 1199 | @Override 1200 | public OnClickListener getOnClickListener() { 1201 | return onClickListener; 1202 | } 1203 | 1204 | } 1205 | 1206 | /** 1207 | * 获取状态栏高度 1208 | * 1209 | * @return 1210 | */ 1211 | public static int getStatusBarHeight() { 1212 | int result = 0; 1213 | int resourceId = Resources.getSystem().getIdentifier("status_bar_height", "dimen", "android"); 1214 | if (resourceId > 0) { 1215 | result = Resources.getSystem().getDimensionPixelSize(resourceId); 1216 | } 1217 | return result; 1218 | } 1219 | 1220 | /** 1221 | * 获取屏幕宽度 1222 | * 1223 | * @return 1224 | */ 1225 | public static int getScreenWidth() { 1226 | return Resources.getSystem().getDisplayMetrics().widthPixels; 1227 | } 1228 | 1229 | /** 1230 | * 将dip或dp值转换为px值 1231 | * 1232 | * @param dipValue dp值 1233 | * @return 1234 | */ 1235 | public static int dip2px(float dipValue) { 1236 | final float scale = Resources.getSystem().getDisplayMetrics().density; 1237 | return (int) (dipValue * scale + 0.5f); 1238 | } 1239 | 1240 | /** 1241 | * 判断父控件是否包含某个子View 1242 | * 1243 | * @param father 1244 | * @param child 1245 | * @return 1246 | */ 1247 | public static boolean hasChildView(ViewGroup father, View child) { 1248 | boolean had = false; 1249 | try { 1250 | had = father.indexOfChild(child) != -1; 1251 | } catch (Exception e) { 1252 | } 1253 | return had; 1254 | } 1255 | } 1256 | -------------------------------------------------------------------------------- /library/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 | -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | TitleBarView 3 | 4 | -------------------------------------------------------------------------------- /screenshot/4.1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AriesHoo/TitleBarView/70e9729a232c66a00a05456f35839f4b6b90c946/screenshot/4.1.gif -------------------------------------------------------------------------------- /screenshot/4.4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AriesHoo/TitleBarView/70e9729a232c66a00a05456f35839f4b6b90c946/screenshot/4.4.gif -------------------------------------------------------------------------------- /screenshot/5.1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AriesHoo/TitleBarView/70e9729a232c66a00a05456f35839f4b6b90c946/screenshot/5.1.gif -------------------------------------------------------------------------------- /screenshot/6.0.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AriesHoo/TitleBarView/70e9729a232c66a00a05456f35839f4b6b90c946/screenshot/6.0.gif -------------------------------------------------------------------------------- /screenshot/7.0.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AriesHoo/TitleBarView/70e9729a232c66a00a05456f35839f4b6b90c946/screenshot/7.0.gif -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':library' 2 | --------------------------------------------------------------------------------