├── .gitignore ├── CoordinatorTabLayout.iml ├── LICENSE.txt ├── README.md ├── README_CN.md ├── build.gradle ├── coordinatortablayout ├── .gitignore ├── build.gradle ├── coordinatortablayout.iml ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── cn │ │ └── hugeterry │ │ └── coordinatortablayout │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── cn │ │ │ └── hugeterry │ │ │ └── coordinatortablayout │ │ │ ├── CoordinatorTabLayout.java │ │ │ ├── listener │ │ │ ├── LoadHeaderImagesListener.java │ │ │ └── OnTabSelectedListener.java │ │ │ └── utils │ │ │ └── SystemView.java │ └── res │ │ ├── anim │ │ ├── anim_dismiss.xml │ │ └── anim_show.xml │ │ ├── drawable │ │ ├── appbarlayout_elevated.xml │ │ └── ic_arrow_white_24dp.xml │ │ ├── layout │ │ └── view_coordinatortablayout.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── cn │ └── hugeterry │ └── coordinatortablayout │ └── ExampleUnitTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── cn │ │ └── hugeterry │ │ └── coordinatortablayout │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── cn │ │ │ └── hugeterry │ │ │ └── coordinatortablayoutdemo │ │ │ ├── IntentUtils.java │ │ │ ├── LoadHeaderImageFromNetworkActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── MainFragment.java │ │ │ ├── MyPagerAdapter.java │ │ │ └── RecyclerAdapter.java │ └── res │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── fragment_main.xml │ │ └── item_main.xml │ │ ├── menu │ │ └── menu_main.xml │ │ ├── mipmap-hdpi │ │ ├── bg_android.jpg │ │ ├── bg_ios.jpg │ │ ├── bg_js.jpg │ │ ├── bg_other.jpg │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── cn │ └── hugeterry │ └── coordinatortablayout │ └── ExampleUnitTest.java ├── settings.gradle └── showUI ├── show1.gif ├── show2.gif ├── show3.gif ├── show4.png └── show5.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | .DS_Store 5 | /build 6 | # built application files 7 | *.apk 8 | *.ap_ 9 | 10 | # files for the dex VM 11 | *.dex 12 | 13 | # Java class files 14 | *.class 15 | .DS_Store 16 | 17 | # generated files 18 | bin/ 19 | gen/ 20 | Wiki/ 21 | 22 | # Local configuration file (sdk path, etc) 23 | local.properties 24 | 25 | # Eclipse project files 26 | .classpath 27 | .project 28 | .settings/ 29 | 30 | # Proguard folder generated by Eclipse 31 | proguard/ 32 | 33 | #Android Studio 34 | build/ 35 | 36 | # Intellij project files 37 | *.iml 38 | *.ipr 39 | *.iws 40 | .idea/ 41 | 42 | #gradle 43 | .gradle/ -------------------------------------------------------------------------------- /CoordinatorTabLayout.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2017 HugeTerry. 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CoordinatorTabLayout 2 | 3 | [![License](https://img.shields.io/badge/license-Apache%202.0-green.svg)](https://github.com/hugeterry/CoordinatorTabLayout/blob/master/LICENSE.txt) 4 | [![Download](https://api.bintray.com/packages/hugeterry/CoordinatorTabLayout/CoordinatorTabLayout/images/download.svg) ](https://bintray.com/hugeterry/CoordinatorTabLayout/CoordinatorTabLayout/_latestVersion) 5 | 6 | [中文版文档](README_CN.md) 7 | 8 | CoordinatorTabLayout is a custom composite control that quickly implements the combination of TabLayout and CoordinatorLayout. 9 | Inherited to the CoordinatorLayout, in the following components used CollapsingToolbarLayout contains TabLayout. 10 | 11 | ![show](showUI/show1.gif) 12 | 13 | 14 | ## Usage 15 | 16 | ### Step 1 17 | 18 | Add the following to your build.gradle: 19 | ```groovy 20 | dependencies { 21 | compile 'cn.hugeterry.coordinatortablayout:coordinatortablayout:1.2.2' 22 | } 23 | ``` 24 | 25 | ### Step 2 26 | 27 | Config in xml: 28 | ```xml 29 | 34 | 35 | 40 | 41 | ``` 42 | 43 | 44 | ### Step 3 45 | 46 | ![show](showUI/show3.gif)
47 | Use it in your own code:
48 | 1.`setTitle(String title)`:Set the CoordinatorTabLayout's title.
49 | 2.`setupWithViewPager(ViewPager viewPager)`:To link the two together.
50 | 3.`setImageArray(int[] imageArray)`:Set the image array of the header according to the number of tabs and pass it to the control.
51 | ```java 52 | //Add the fragment to the viewpager 53 | initFragments(); 54 | initViewPager(); 55 | //Image array 56 | mImageArray = new int[]{ 57 | R.mipmap.bg_android, 58 | R.mipmap.bg_ios, 59 | R.mipmap.bg_js, 60 | R.mipmap.bg_other}; 61 | 62 | mCoordinatorTabLayout = (CoordinatorTabLayout) findViewById(R.id.coordinatortablayout); 63 | mCoordinatorTabLayout.setTitle("Demo") 64 | .setImageArray(mImageArray) 65 | .setupWithViewPager(mViewPager); 66 | ``` 67 | 68 | Finish, enjoy it. 69 | 70 | 71 | ## More 72 | 73 | ### Set the content scrim 74 | 75 | ![show](showUI/show2.gif) 76 | 77 | `setImageArray(int[] imageArray, int[] colorArray)`:Set the color array to use for the content scrim for each tab. 78 | ```java 79 | mColorArray = new int[]{ 80 | android.R.color.holo_blue_light, 81 | android.R.color.holo_red_light, 82 | android.R.color.holo_orange_light, 83 | android.R.color.holo_green_light}; 84 | mCoordinatorTabLayout.setImageArray(mImageArray, mColorArray); 85 | ``` 86 | 87 | ### Set translucent status bar 88 | 89 | ![show](showUI/show4.png) 90 | 91 | `setTranslucentStatusBar(Activity activity)`:Set translucent status bar,Support android4.4 and above. 92 | ```java 93 | mCoordinatorTabLayout.setTranslucentStatusBar(activity); 94 | ``` 95 | 96 | ### Set translucent navigation bar 97 | 98 | ![show](showUI/show5.jpg) 99 | 100 | `setTranslucentNavigationBar(Activity activity)`:Set translucent navigation bar,Support android4.4 and above. 101 | ```java 102 | mCoordinatorTabLayout.setTranslucentNavigationBar(activity); 103 | ``` 104 | 105 | ### Set back enable 106 | `setBackEnable(Boolean canBack)`:To enable the Up button for an activity that has a parent activity. 107 | ```java 108 | @Override 109 | protected void onCreate(Bundle savedInstanceState) { 110 | ... 111 | mCoordinatorTabLayout.setBackEnable(true); 112 | ... 113 | } 114 | @Override 115 | public boolean onOptionsItemSelected(MenuItem item) { 116 | if (item.getItemId() == android.R.id.home) { 117 | finish(); 118 | } 119 | return super.onOptionsItemSelected(item); 120 | } 121 | ``` 122 | 123 | ### Load header images from network 124 | 125 | `setLoadHeaderImagesListener(LoadHeaderImagesListener loadHeaderImagesListener)`:Set the listener that gets the header images. 126 | ```java 127 | @Override 128 | protected void onCreate(Bundle savedInstanceState) { 129 | ... 130 | mCoordinatorTabLayout.setTitle("Demo") 131 | .setBackEnable(true) 132 | .setContentScrimColorArray(mColorArray) 133 | .setLoadHeaderImagesListener(new LoadHeaderImagesListener() { 134 | @Override 135 | public void loadHeaderImages(ImageView imageView, TabLayout.Tab tab) { 136 | switch (tab.getPosition()) { 137 | case 0: 138 | //load header images 139 | break; 140 | ... 141 | } 142 | } 143 | }) 144 | .setupWithViewPager(mViewPager); 145 | } 146 | ``` 147 | You also can load header images using glide/picasso,[Sample](https://github.com/hugeterry/CoordinatorTabLayout/blob/master/sample/src/main/java/cn/hugeterry/coordinatortablayoutdemo/LoadHeaderImageFromNetworkActivity.java) 148 | 149 | ### Set the behavior mode for the Tabs in this layout 150 | 151 | `setTabMode(@TabLayout.Mode int mode)`:The valid input options are:MODE_FIXED,MODE_SCROLLABLE 152 | ```java 153 | mCoordinatorTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE); 154 | ``` 155 | 156 | ### Add a CoordinatorTabLayout.OnTabSelectedListener 157 | 158 | `addOnTabSelectedListener(OnTabSelectedListener onTabSelectedListener)`:Add a CoordinatorTabLayout.OnTabSelectedListener that will be invoked when tab selection changes. 159 | ```java 160 | mCoordinatorTabLayout.addOnTabSelectedListener(new OnTabSelectedListener() { 161 | @Override 162 | public void onTabSelected(TabLayout.Tab tab) { 163 | 164 | } 165 | 166 | @Override 167 | public void onTabUnselected(TabLayout.Tab tab) { 168 | 169 | } 170 | 171 | @Override 172 | public void onTabReselected(TabLayout.Tab tab) { 173 | 174 | } 175 | }) 176 | ``` 177 | 178 | ### Gets the child control 179 | `getActionBar()`:get the ActionBar
180 | `getTabLayout()`:get the TabLayout
181 | `getImageView()`:get the ImageView 182 | 183 | [More code](https://github.com/hugeterry/CoordinatorTabLayout/blob/master/sample/src/main/java/cn/hugeterry/coordinatortablayoutdemo/MainActivity.java) 184 | 185 | 186 | ## Attributes 187 | - `app:contentScrim` -> color.Defaults to ?attr/colorPrimary 188 | - `app:tabIndicatorColor` -> color. 189 | - `app:tabTextColor` -> color. 190 | 191 | ## Demo 192 | [http://fir.im/ctlayout](http://fir.im/ctlayout) 193 | 194 | ## LICENSE 195 | Copyright 2017 HugeTerry. 196 | Licensed under the Apache License, Version 2.0 (the "License"); 197 | you may not use this file except in compliance with the License. 198 | You may obtain a copy of the License at 199 | 200 | http://www.apache.org/licenses/LICENSE-2.0 201 | 202 | Unless required by applicable law or agreed to in writing, software 203 | distributed under the License is distributed on an "AS IS" BASIS, 204 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 205 | See the License for the specific language governing permissions and 206 | limitations under the License. 207 | 208 | -------------------------------------------------------------------------------- /README_CN.md: -------------------------------------------------------------------------------- 1 | # CoordinatorTabLayout 2 | 3 | [![License](https://img.shields.io/badge/license-Apache%202.0-green.svg)](https://github.com/hugeterry/CoordinatorTabLayout/blob/master/LICENSE.txt) 4 | [![Download](https://api.bintray.com/packages/hugeterry/CoordinatorTabLayout/CoordinatorTabLayout/images/download.svg) ](https://bintray.com/hugeterry/CoordinatorTabLayout/CoordinatorTabLayout/_latestVersion) 5 | 6 | CoordinatorTabLayout是一个自定义组合控件,可快速实现TabLayout与CoordinatorLayout相结合的样式 7 | 继承至CoordinatorLayout, 在该组件下面使用了CollapsingToolbarLayout包含TabLayout 8 | 9 | [相关文档介绍:http://hugeterry.cn/dreams/559](http://hugeterry.cn/dreams/559) 10 | 11 | 12 | ![show](showUI/show1.gif) 13 | 14 | 15 | ## 用法 16 | 17 | ### Step 1 18 | 19 | 在gradle文件中加入下面的依赖: 20 | ```groovy 21 | dependencies { 22 | compile 'cn.hugeterry.coordinatortablayout:coordinatortablayout:1.2.2' 23 | } 24 | ``` 25 | 26 | ### Step 2 27 | 28 | 在你自己的XML中使用它: 29 | ```xml 30 | 35 | 36 | 41 | 42 | ``` 43 | 44 | 45 | ### Step 3 46 | 47 | ![show](showUI/show3.gif)
48 | 在使用它的界面添加以下设置:
49 | 1.`setTitle(String title)`:设置Toolbar标题
50 | 2.`setupWithViewPager(ViewPager viewPager)`:将写好的viewpager设置到该控件当中
51 | 3.`setImageArray(int[] imageArray)`:根据tab数量设置好头部的图片数组,并传到该控件当中 52 | ```java 53 | //构建写好的fragment加入到viewpager中 54 | initFragments(); 55 | initViewPager(); 56 | //头部的图片数组 57 | mImageArray = new int[]{ 58 | R.mipmap.bg_android, 59 | R.mipmap.bg_ios, 60 | R.mipmap.bg_js, 61 | R.mipmap.bg_other}; 62 | 63 | mCoordinatorTabLayout = (CoordinatorTabLayout) findViewById(R.id.coordinatortablayout); 64 | mCoordinatorTabLayout.setTitle("Demo") 65 | .setImageArray(mImageArray) 66 | .setupWithViewPager(mViewPager); 67 | ``` 68 | 69 | 大功告成,好好享用吧 70 | 71 | 72 | ## 更多功能 73 | 74 | ### 添加折叠后的颜色变化效果 75 | 76 | ![show](showUI/show2.gif) 77 | 78 | `setImageArray(int[] imageArray, int[] colorArray)`:如果你想要有头部折叠后的颜色变化,可将之前设置好的图片数组以及根据tab数量设置的颜色数组传到该控件当中 79 | ```java 80 | mColorArray = new int[]{ 81 | android.R.color.holo_blue_light, 82 | android.R.color.holo_red_light, 83 | android.R.color.holo_orange_light, 84 | android.R.color.holo_green_light}; 85 | mCoordinatorTabLayout.setImageArray(mImageArray, mColorArray); 86 | ``` 87 | 88 | ### 设置头部状态栏透明 89 | 90 | ![show](showUI/show4.png) 91 | 92 | `setTranslucentStatusBar(Activity activity)`:设置头部状态栏透明,在android4.4 及以上版本生效 93 | ```java 94 | mCoordinatorTabLayout.setTranslucentStatusBar(activity); 95 | ``` 96 | 97 | ### 设置导航栏透明 98 | 99 | ![show](showUI/show5.jpg) 100 | 101 | `setTranslucentNavigationBar(Activity activity)`:设置导航栏透明,在android4.4 及以上版本生效 102 | ```java 103 | mCoordinatorTabLayout.setTranslucentNavigationBar(activity); 104 | ``` 105 | 106 | ### 添加返回 107 | 108 | `setBackEnable(Boolean canBack)`:设置Toolbar的返回按钮 109 | ```java 110 | @Override 111 | protected void onCreate(Bundle savedInstanceState) { 112 | ... 113 | mCoordinatorTabLayout.setBackEnable(true); 114 | ... 115 | } 116 | @Override 117 | public boolean onOptionsItemSelected(MenuItem item) { 118 | if (item.getItemId() == android.R.id.home) { 119 | finish(); 120 | } 121 | return super.onOptionsItemSelected(item); 122 | } 123 | ``` 124 | 125 | ### 通过网络加载头部图片 126 | 127 | 选择用网络来加载图片。可实现以下接口: 128 | `setLoadHeaderImagesListener(LoadHeaderImagesListener loadHeaderImagesListener)`:设置获取头部图片的操作 129 | ```java 130 | @Override 131 | protected void onCreate(Bundle savedInstanceState) { 132 | ... 133 | mCoordinatorTabLayout.setTitle("Demo") 134 | .setBackEnable(true) 135 | .setContentScrimColorArray(mColorArray) 136 | .setLoadHeaderImagesListener(new LoadHeaderImagesListener() { 137 | @Override 138 | public void loadHeaderImages(ImageView imageView, TabLayout.Tab tab) { 139 | switch (tab.getPosition()) { 140 | case 0: 141 | //加载图片 142 | break; 143 | ... 144 | } 145 | } 146 | }) 147 | .setupWithViewPager(mViewPager); 148 | } 149 | ``` 150 | 你也可以选择用Glide/Picasso等网络框架来实现,[代码例子](https://github.com/hugeterry/CoordinatorTabLayout/blob/master/sample/src/main/java/cn/hugeterry/coordinatortablayoutdemo/LoadHeaderImageFromNetworkActivity.java) 151 | 152 | ### 设置tab可滑动(当tab过多时) 153 | 154 | `setTabMode(@TabLayout.Mode int mode)`:可设置tablayout的行为模式 155 | ```java 156 | mCoordinatorTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE); 157 | ``` 158 | 159 | ### 设置tab的选中监听器 160 | 161 | `addOnTabSelectedListener(OnTabSelectedListener onTabSelectedListener)`:对tab点击前中后进行操作 162 | ```java 163 | mCoordinatorTabLayout.addOnTabSelectedListener(new OnTabSelectedListener() { 164 | @Override 165 | public void onTabSelected(TabLayout.Tab tab) { 166 | 167 | } 168 | 169 | @Override 170 | public void onTabUnselected(TabLayout.Tab tab) { 171 | 172 | } 173 | 174 | @Override 175 | public void onTabReselected(TabLayout.Tab tab) { 176 | 177 | } 178 | }) 179 | ``` 180 | 181 | ### 获取子控件 182 | 183 | `getActionBar()`:获取该组件中的ActionBar
184 | `getTabLayout()`:获取该组件中的TabLayout
185 | `getImageView()`:获取该组件中的ImageView 186 | 187 | [更多代码](https://github.com/hugeterry/CoordinatorTabLayout/blob/master/sample/src/main/java/cn/hugeterry/coordinatortablayoutdemo/MainActivity.java) 188 | 189 | 190 | ## 属性 191 | 192 | - `app:contentScrim` -> color.默认为?attr/colorPrimary 193 | - `app:tabIndicatorColor` -> color. 194 | - `app:tabTextColor` -> color. 195 | 196 | ## Demo 197 | [http://fir.im/ctlayout](http://fir.im/ctlayout) 198 | 199 | ## LICENSE 200 | Copyright 2017 HugeTerry. 201 | Licensed under the Apache License, Version 2.0 (the "License"); 202 | you may not use this file except in compliance with the License. 203 | You may obtain a copy of the License at 204 | 205 | http://www.apache.org/licenses/LICENSE-2.0 206 | 207 | Unless required by applicable law or agreed to in writing, software 208 | distributed under the License is distributed on an "AS IS" BASIS, 209 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 210 | See the License for the specific language governing permissions and 211 | limitations under the License. 212 | 213 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | google() 6 | jcenter() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:3.0.1' 10 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6' 11 | classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.0.0" 12 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /coordinatortablayout/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /coordinatortablayout/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | apply plugin: 'com.jfrog.bintray' 4 | 5 | version = "1.2.2" 6 | 7 | android { 8 | compileSdkVersion 25 9 | buildToolsVersion '26.0.2' 10 | 11 | defaultConfig { 12 | minSdkVersion 15 13 | targetSdkVersion 25 14 | versionCode 10 15 | versionName "1.2.2" 16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 17 | 18 | } 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | compile fileTree(dir: 'libs', include: ['*.jar']) 29 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 30 | exclude group: 'com.android.support', module: 'support-annotations' 31 | }) 32 | compile 'com.android.support:appcompat-v7:25.3.1' 33 | compile 'com.android.support:design:25.3.1' 34 | testCompile 'junit:junit:4.12' 35 | } 36 | 37 | def siteUrl = 'https://github.com/hugeterry/CoordinatorTabLayout' 38 | def gitUrl = 'https://github.com/hugeterry/CoordinatorTabLayout.git' 39 | group = "cn.hugeterry.coordinatortablayout" 40 | install { 41 | repositories.mavenInstaller { 42 | pom { 43 | project { 44 | packaging 'aar' 45 | name '' 46 | url siteUrl 47 | 48 | licenses { 49 | license { 50 | name 'The Apache Software License, Version 2.0' 51 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 52 | } 53 | } 54 | developers { 55 | developer { 56 | id 'hugeterry' 57 | name 'HugeTerry' 58 | email 'xuxt-314@qq.com' 59 | } 60 | } 61 | scm { 62 | connection gitUrl 63 | developerConnection gitUrl 64 | url siteUrl 65 | } 66 | } 67 | } 68 | } 69 | } 70 | task sourcesJar(type: Jar) { 71 | from android.sourceSets.main.java.srcDirs 72 | classifier = 'sources' 73 | } 74 | task javadoc(type: Javadoc) { 75 | source = android.sourceSets.main.java.srcDirs 76 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 77 | } 78 | task javadocJar(type: Jar, dependsOn: javadoc) { 79 | classifier = 'javadoc' 80 | from javadoc.destinationDir 81 | } 82 | artifacts { 83 | archives javadocJar 84 | archives sourcesJar 85 | } 86 | Properties properties = new Properties() 87 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 88 | bintray { 89 | user = properties.getProperty("bintray.user") 90 | key = properties.getProperty("bintray.apikey") 91 | configurations = ['archives'] 92 | pkg { 93 | repo = "CoordinatorTabLayout" 94 | name = "CoordinatorTabLayout" 95 | websiteUrl = siteUrl 96 | vcsUrl = gitUrl 97 | licenses = ["Apache-2.0"] 98 | publish = true 99 | } 100 | } -------------------------------------------------------------------------------- /coordinatortablayout/coordinatortablayout.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /coordinatortablayout/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 /Users/admin/Library/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 | -------------------------------------------------------------------------------- /coordinatortablayout/src/androidTest/java/cn/hugeterry/coordinatortablayout/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package cn.hugeterry.coordinatortablayout; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("cn.hugeterry.coordinatortablayout.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /coordinatortablayout/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /coordinatortablayout/src/main/java/cn/hugeterry/coordinatortablayout/CoordinatorTabLayout.java: -------------------------------------------------------------------------------- 1 | package cn.hugeterry.coordinatortablayout; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.content.res.ColorStateList; 6 | import android.content.res.TypedArray; 7 | import android.graphics.Color; 8 | import android.os.Build; 9 | import android.support.annotation.NonNull; 10 | import android.support.design.widget.CollapsingToolbarLayout; 11 | import android.support.design.widget.CoordinatorLayout; 12 | import android.support.design.widget.TabLayout; 13 | import android.support.v4.content.ContextCompat; 14 | import android.support.v4.view.ViewPager; 15 | import android.support.v7.app.ActionBar; 16 | import android.support.v7.app.AppCompatActivity; 17 | import android.support.v7.widget.Toolbar; 18 | import android.util.AttributeSet; 19 | import android.util.TypedValue; 20 | import android.view.LayoutInflater; 21 | import android.view.View; 22 | import android.view.ViewGroup; 23 | import android.view.WindowManager; 24 | import android.view.animation.AnimationUtils; 25 | import android.widget.ImageView; 26 | 27 | import cn.hugeterry.coordinatortablayout.listener.LoadHeaderImagesListener; 28 | import cn.hugeterry.coordinatortablayout.listener.OnTabSelectedListener; 29 | import cn.hugeterry.coordinatortablayout.utils.SystemView; 30 | 31 | /** 32 | * @author hugeterry(http://hugeterry.cn) 33 | */ 34 | 35 | public class CoordinatorTabLayout extends CoordinatorLayout { 36 | private int[] mImageArray, mColorArray; 37 | 38 | private Context mContext; 39 | private Toolbar mToolbar; 40 | private ActionBar mActionbar; 41 | private TabLayout mTabLayout; 42 | private ImageView mImageView; 43 | private CollapsingToolbarLayout mCollapsingToolbarLayout; 44 | private LoadHeaderImagesListener mLoadHeaderImagesListener; 45 | private OnTabSelectedListener mOnTabSelectedListener; 46 | 47 | public CoordinatorTabLayout(Context context) { 48 | super(context); 49 | mContext = context; 50 | } 51 | 52 | public CoordinatorTabLayout(Context context, AttributeSet attrs) { 53 | super(context, attrs); 54 | mContext = context; 55 | if (!isInEditMode()) { 56 | initView(context); 57 | initWidget(context, attrs); 58 | } 59 | } 60 | 61 | public CoordinatorTabLayout(Context context, AttributeSet attrs, int defStyleAttr) { 62 | super(context, attrs, defStyleAttr); 63 | mContext = context; 64 | if (!isInEditMode()) { 65 | initView(context); 66 | initWidget(context, attrs); 67 | } 68 | } 69 | 70 | private void initView(Context context) { 71 | LayoutInflater.from(context).inflate(R.layout.view_coordinatortablayout, this, true); 72 | initToolbar(); 73 | mCollapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsingtoolbarlayout); 74 | mTabLayout = (TabLayout) findViewById(R.id.tabLayout); 75 | mImageView = (ImageView) findViewById(R.id.imageview); 76 | } 77 | 78 | private void initWidget(Context context, AttributeSet attrs) { 79 | TypedArray typedArray = context.obtainStyledAttributes(attrs 80 | , R.styleable.CoordinatorTabLayout); 81 | 82 | TypedValue typedValue = new TypedValue(); 83 | mContext.getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true); 84 | int contentScrimColor = typedArray.getColor( 85 | R.styleable.CoordinatorTabLayout_contentScrim, typedValue.data); 86 | mCollapsingToolbarLayout.setContentScrimColor(contentScrimColor); 87 | 88 | int tabIndicatorColor = typedArray.getColor(R.styleable.CoordinatorTabLayout_tabIndicatorColor, Color.WHITE); 89 | mTabLayout.setSelectedTabIndicatorColor(tabIndicatorColor); 90 | 91 | int tabTextColor = typedArray.getColor(R.styleable.CoordinatorTabLayout_tabTextColor, Color.WHITE); 92 | mTabLayout.setTabTextColors(ColorStateList.valueOf(tabTextColor)); 93 | typedArray.recycle(); 94 | } 95 | 96 | private void initToolbar() { 97 | mToolbar = (Toolbar) findViewById(R.id.toolbar); 98 | ((AppCompatActivity) mContext).setSupportActionBar(mToolbar); 99 | mActionbar = ((AppCompatActivity) mContext).getSupportActionBar(); 100 | } 101 | 102 | /** 103 | * 设置Toolbar标题 104 | * 105 | * @param title 标题 106 | * @return CoordinatorTabLayout 107 | */ 108 | public CoordinatorTabLayout setTitle(String title) { 109 | if (mActionbar != null) { 110 | mActionbar.setTitle(title); 111 | } 112 | return this; 113 | } 114 | 115 | /** 116 | * 设置Toolbar显示返回按钮及标题 117 | * 118 | * @param canBack 是否返回 119 | * @return CoordinatorTabLayout 120 | */ 121 | public CoordinatorTabLayout setBackEnable(Boolean canBack) { 122 | if (canBack && mActionbar != null) { 123 | mActionbar.setDisplayHomeAsUpEnabled(true); 124 | mActionbar.setHomeAsUpIndicator(R.drawable.ic_arrow_white_24dp); 125 | } 126 | return this; 127 | } 128 | 129 | /** 130 | * 设置每个tab对应的头部图片 131 | * 132 | * @param imageArray 图片数组 133 | * @return CoordinatorTabLayout 134 | */ 135 | public CoordinatorTabLayout setImageArray(@NonNull int[] imageArray) { 136 | mImageArray = imageArray; 137 | return this; 138 | } 139 | 140 | /** 141 | * 设置每个tab对应的头部照片和ContentScrimColor 142 | * 143 | * @param imageArray 图片数组 144 | * @param colorArray ContentScrimColor数组 145 | * @return CoordinatorTabLayout 146 | */ 147 | public CoordinatorTabLayout setImageArray(@NonNull int[] imageArray, @NonNull int[] colorArray) { 148 | mImageArray = imageArray; 149 | mColorArray = colorArray; 150 | return this; 151 | } 152 | 153 | /** 154 | * 设置每个tab对应的ContentScrimColor 155 | * 156 | * @param colorArray 图片数组 157 | * @return CoordinatorTabLayout 158 | */ 159 | public CoordinatorTabLayout setContentScrimColorArray(@NonNull int[] colorArray) { 160 | mColorArray = colorArray; 161 | return this; 162 | } 163 | 164 | private void setupTabLayout() { 165 | mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { 166 | @Override 167 | public void onTabSelected(TabLayout.Tab tab) { 168 | mImageView.startAnimation(AnimationUtils.loadAnimation(mContext, R.anim.anim_dismiss)); 169 | if (mLoadHeaderImagesListener == null) { 170 | if (mImageArray != null) { 171 | mImageView.setImageResource(mImageArray[tab.getPosition()]); 172 | } 173 | } else { 174 | mLoadHeaderImagesListener.loadHeaderImages(mImageView, tab); 175 | } 176 | if (mColorArray != null) { 177 | mCollapsingToolbarLayout.setContentScrimColor( 178 | ContextCompat.getColor( 179 | mContext, mColorArray[tab.getPosition()])); 180 | } 181 | mImageView.setAnimation(AnimationUtils.loadAnimation(mContext, R.anim.anim_show)); 182 | 183 | if (mOnTabSelectedListener != null) { 184 | mOnTabSelectedListener.onTabSelected(tab); 185 | } 186 | 187 | } 188 | 189 | @Override 190 | public void onTabUnselected(TabLayout.Tab tab) { 191 | if (mOnTabSelectedListener != null) { 192 | mOnTabSelectedListener.onTabUnselected(tab); 193 | } 194 | } 195 | 196 | @Override 197 | public void onTabReselected(TabLayout.Tab tab) { 198 | if (mOnTabSelectedListener != null) { 199 | mOnTabSelectedListener.onTabReselected(tab); 200 | } 201 | } 202 | }); 203 | } 204 | 205 | /** 206 | * 设置TabLayout TabMode 207 | * 208 | * @param mode 209 | * @return CoordinatorTabLayout 210 | */ 211 | public CoordinatorTabLayout setTabMode(@TabLayout.Mode int mode) { 212 | mTabLayout.setTabMode(mode); 213 | return this; 214 | } 215 | 216 | /** 217 | * 设置与该组件搭配的ViewPager 218 | * 219 | * @param viewPager 与TabLayout结合的ViewPager 220 | * @return CoordinatorTabLayout 221 | */ 222 | public CoordinatorTabLayout setupWithViewPager(ViewPager viewPager) { 223 | setupTabLayout(); 224 | mTabLayout.setupWithViewPager(viewPager); 225 | return this; 226 | } 227 | 228 | /** 229 | * 获取该组件中的ActionBar 230 | */ 231 | public ActionBar getActionBar() { 232 | return mActionbar; 233 | } 234 | 235 | /** 236 | * 获取该组件中的TabLayout 237 | */ 238 | public TabLayout getTabLayout() { 239 | return mTabLayout; 240 | } 241 | 242 | /** 243 | * 获取该组件中的ImageView 244 | */ 245 | public ImageView getImageView() { 246 | return mImageView; 247 | } 248 | 249 | /** 250 | * 设置LoadHeaderImagesListener 251 | * 252 | * @param loadHeaderImagesListener 设置LoadHeaderImagesListener 253 | * @return CoordinatorTabLayout 254 | */ 255 | public CoordinatorTabLayout setLoadHeaderImagesListener(LoadHeaderImagesListener loadHeaderImagesListener) { 256 | mLoadHeaderImagesListener = loadHeaderImagesListener; 257 | return this; 258 | } 259 | 260 | /** 261 | * 设置onTabSelectedListener 262 | * 263 | * @param onTabSelectedListener 设置onTabSelectedListener 264 | * @return CoordinatorTabLayout 265 | */ 266 | public CoordinatorTabLayout addOnTabSelectedListener(OnTabSelectedListener onTabSelectedListener) { 267 | mOnTabSelectedListener = onTabSelectedListener; 268 | return this; 269 | } 270 | 271 | /** 272 | * 设置透明状态栏 273 | * 274 | * @param activity 当前展示的activity 275 | * @return CoordinatorTabLayout 276 | */ 277 | public CoordinatorTabLayout setTranslucentStatusBar(@NonNull Activity activity) { 278 | 279 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { 280 | return this; 281 | } 282 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 283 | activity.getWindow().setStatusBarColor(Color.TRANSPARENT); 284 | activity.getWindow() 285 | .getDecorView() 286 | .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); 287 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 288 | activity.getWindow() 289 | .setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, 290 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 291 | } 292 | 293 | if (mToolbar != null) { 294 | ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) mToolbar.getLayoutParams(); 295 | layoutParams.setMargins( 296 | layoutParams.leftMargin, 297 | layoutParams.topMargin + SystemView.getStatusBarHeight(activity), 298 | layoutParams.rightMargin, 299 | layoutParams.bottomMargin); 300 | } 301 | 302 | return this; 303 | } 304 | 305 | /** 306 | * 设置沉浸式 307 | * 308 | * @param activity 当前展示的activity 309 | * @return CoordinatorTabLayout 310 | */ 311 | public CoordinatorTabLayout setTranslucentNavigationBar(@NonNull Activity activity) { 312 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { 313 | return this; 314 | } else { 315 | mToolbar.setPadding(0, SystemView.getStatusBarHeight(activity) >> 1, 0, 0); 316 | } 317 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 318 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); 319 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 320 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); 321 | activity.getWindow().setStatusBarColor(Color.TRANSPARENT); 322 | } else { 323 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 324 | } 325 | return this; 326 | } 327 | 328 | } -------------------------------------------------------------------------------- /coordinatortablayout/src/main/java/cn/hugeterry/coordinatortablayout/listener/LoadHeaderImagesListener.java: -------------------------------------------------------------------------------- 1 | package cn.hugeterry.coordinatortablayout.listener; 2 | 3 | import android.support.design.widget.TabLayout; 4 | import android.widget.ImageView; 5 | 6 | /** 7 | * @author hugeterry(http://hugeterry.cn) 8 | */ 9 | 10 | public interface LoadHeaderImagesListener { 11 | void loadHeaderImages(ImageView imageView, TabLayout.Tab tab); 12 | } 13 | -------------------------------------------------------------------------------- /coordinatortablayout/src/main/java/cn/hugeterry/coordinatortablayout/listener/OnTabSelectedListener.java: -------------------------------------------------------------------------------- 1 | package cn.hugeterry.coordinatortablayout.listener; 2 | 3 | import android.support.design.widget.TabLayout; 4 | 5 | /** 6 | * @author hugeterry(http://hugeterry.cn) 7 | */ 8 | 9 | public interface OnTabSelectedListener { 10 | 11 | public void onTabSelected(TabLayout.Tab tab); 12 | 13 | public void onTabUnselected(TabLayout.Tab tab); 14 | 15 | public void onTabReselected(TabLayout.Tab tab); 16 | } 17 | -------------------------------------------------------------------------------- /coordinatortablayout/src/main/java/cn/hugeterry/coordinatortablayout/utils/SystemView.java: -------------------------------------------------------------------------------- 1 | package cn.hugeterry.coordinatortablayout.utils; 2 | 3 | import android.content.Context; 4 | 5 | /** 6 | * @author hugeterry(http://hugeterry.cn) 7 | */ 8 | 9 | public class SystemView { 10 | public static int getStatusBarHeight(Context context) { 11 | int result = 0; 12 | int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); 13 | if (resourceId > 0) { 14 | result = context.getResources().getDimensionPixelSize(resourceId); 15 | } 16 | return result; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /coordinatortablayout/src/main/res/anim/anim_dismiss.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | -------------------------------------------------------------------------------- /coordinatortablayout/src/main/res/anim/anim_show.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | -------------------------------------------------------------------------------- /coordinatortablayout/src/main/res/drawable/appbarlayout_elevated.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | -------------------------------------------------------------------------------- /coordinatortablayout/src/main/res/drawable/ic_arrow_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /coordinatortablayout/src/main/res/layout/view_coordinatortablayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 21 | 22 | 29 | 30 | 38 | 39 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /coordinatortablayout/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /coordinatortablayout/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | imageview 3 | 4 | -------------------------------------------------------------------------------- /coordinatortablayout/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /coordinatortablayout/src/test/java/cn/hugeterry/coordinatortablayout/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package cn.hugeterry.coordinatortablayout; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hugeterry/CoordinatorTabLayout/c565332bcf9479dace0e0697973722c7f2c78c0f/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Dec 31 16:08:46 CST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion '26.0.2' 6 | defaultConfig { 7 | applicationId "cn.hugeterry.coordinatortablayout" 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:25.3.1' 28 | testCompile 'junit:junit:4.12' 29 | 30 | compile project(':coordinatortablayout') 31 | compile 'com.github.bumptech.glide:glide:3.7.0' 32 | } 33 | -------------------------------------------------------------------------------- /sample/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 /Users/admin/Library/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 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/cn/hugeterry/coordinatortablayout/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package cn.hugeterry.coordinatortablayout; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("cn.hugeterry.coordinatortablayout", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /sample/src/main/java/cn/hugeterry/coordinatortablayoutdemo/IntentUtils.java: -------------------------------------------------------------------------------- 1 | package cn.hugeterry.coordinatortablayoutdemo; 2 | 3 | /** 4 | * Created by hugeterry(http://hugeterry.cn) 5 | */ 6 | 7 | import android.content.Context; 8 | import android.content.Intent; 9 | import android.net.Uri; 10 | 11 | public class IntentUtils { 12 | 13 | private IntentUtils() { 14 | throw new UnsupportedOperationException("This class cannot be instantiated, and its methods must be called directly."); 15 | } 16 | 17 | public static void openUrl(Context context, String url) { 18 | Uri uri = Uri.parse(url); 19 | Intent intent = new Intent(Intent.ACTION_VIEW, uri); 20 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 21 | context.startActivity(intent); 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /sample/src/main/java/cn/hugeterry/coordinatortablayoutdemo/LoadHeaderImageFromNetworkActivity.java: -------------------------------------------------------------------------------- 1 | package cn.hugeterry.coordinatortablayoutdemo; 2 | 3 | import android.os.Bundle; 4 | import android.support.design.widget.TabLayout; 5 | import android.support.v4.app.Fragment; 6 | import android.support.v4.view.ViewPager; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.view.Menu; 9 | import android.view.MenuItem; 10 | import android.view.Window; 11 | import android.view.WindowManager; 12 | import android.widget.ImageView; 13 | 14 | import com.bumptech.glide.Glide; 15 | 16 | import java.util.ArrayList; 17 | 18 | import cn.hugeterry.coordinatortablayout.CoordinatorTabLayout; 19 | import cn.hugeterry.coordinatortablayout.listener.LoadHeaderImagesListener; 20 | 21 | /** 22 | * Created by hugeterry(http://hugeterry.cn) 23 | */ 24 | public class LoadHeaderImageFromNetworkActivity extends AppCompatActivity { 25 | private CoordinatorTabLayout mCoordinatorTabLayout; 26 | private int[] mColorArray; 27 | private ArrayList mFragments; 28 | private final String[] mTitles = {"Android", "Web", "iOS", "Other"}; 29 | private ViewPager mViewPager; 30 | 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | requestWindowFeature(Window.FEATURE_NO_TITLE); 35 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 36 | WindowManager.LayoutParams.FLAG_FULLSCREEN); 37 | setContentView(R.layout.activity_main); 38 | initFragments(); 39 | initViewPager(); 40 | mColorArray = new int[]{ 41 | android.R.color.holo_blue_light, 42 | android.R.color.holo_red_light, 43 | android.R.color.holo_orange_light, 44 | android.R.color.holo_green_light}; 45 | 46 | mCoordinatorTabLayout = (CoordinatorTabLayout) findViewById(R.id.coordinatortablayout); 47 | mCoordinatorTabLayout.setTranslucentStatusBar(this) 48 | .setTitle("Demo") 49 | .setBackEnable(true) 50 | .setContentScrimColorArray(mColorArray) 51 | .setLoadHeaderImagesListener(new LoadHeaderImagesListener() { 52 | @Override 53 | public void loadHeaderImages(ImageView imageView, TabLayout.Tab tab) { 54 | switch (tab.getPosition()) { 55 | case 0: 56 | loadImages(imageView, "https://raw.githubusercontent.com/hugeterry/CoordinatorTabLayout/master/sample/src/main/res/mipmap-hdpi/bg_android.jpg"); 57 | break; 58 | case 1: 59 | loadImages(imageView, "https://raw.githubusercontent.com/hugeterry/CoordinatorTabLayout/master/sample/src/main/res/mipmap-hdpi/bg_js.jpg"); 60 | break; 61 | case 2: 62 | loadImages(imageView, "https://raw.githubusercontent.com/hugeterry/CoordinatorTabLayout/master/sample/src/main/res/mipmap-hdpi/bg_ios.jpg"); 63 | break; 64 | case 3: 65 | loadImages(imageView, "https://raw.githubusercontent.com/hugeterry/CoordinatorTabLayout/master/sample/src/main/res/mipmap-hdpi/bg_other.jpg"); 66 | break; 67 | default: 68 | break; 69 | } 70 | } 71 | }) 72 | .setupWithViewPager(mViewPager); 73 | } 74 | 75 | private void loadImages(ImageView imageView, String url) { 76 | Glide.with(LoadHeaderImageFromNetworkActivity.this).load(url).into(imageView); 77 | } 78 | 79 | private void initFragments() { 80 | mFragments = new ArrayList<>(); 81 | for (String title : mTitles) { 82 | mFragments.add(MainFragment.getInstance(title)); 83 | } 84 | } 85 | 86 | private void initViewPager() { 87 | mViewPager = (ViewPager) findViewById(R.id.vp); 88 | mViewPager.setOffscreenPageLimit(4); 89 | mViewPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager(), mFragments, mTitles)); 90 | } 91 | 92 | @Override 93 | public boolean onOptionsItemSelected(MenuItem item) { 94 | if (item.getItemId() == android.R.id.home) { 95 | finish(); 96 | } 97 | 98 | switch (item.getItemId()) { 99 | case R.id.action_about: 100 | IntentUtils.openUrl(this, "https://github.com/hugeterry/CoordinatorTabLayout"); 101 | break; 102 | case R.id.action_about_me: 103 | IntentUtils.openUrl(this, "http://hugeterry.cn/about"); 104 | break; 105 | } 106 | return super.onOptionsItemSelected(item); 107 | } 108 | 109 | @Override 110 | public boolean onCreateOptionsMenu(Menu menu) { 111 | getMenuInflater().inflate(R.menu.menu_main, menu); 112 | return super.onCreateOptionsMenu(menu); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /sample/src/main/java/cn/hugeterry/coordinatortablayoutdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package cn.hugeterry.coordinatortablayoutdemo; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.view.ViewPager; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.view.Menu; 8 | import android.view.MenuItem; 9 | 10 | import java.util.ArrayList; 11 | 12 | import cn.hugeterry.coordinatortablayout.CoordinatorTabLayout; 13 | 14 | /** 15 | * Created by hugeterry(http://hugeterry.cn) 16 | */ 17 | public class MainActivity extends AppCompatActivity { 18 | private CoordinatorTabLayout mCoordinatorTabLayout; 19 | private int[] mImageArray, mColorArray; 20 | private ArrayList mFragments; 21 | private final String[] mTitles = {"Android", "iOS", "Web", "Other"}; 22 | private ViewPager mViewPager; 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | setContentView(R.layout.activity_main); 28 | initFragments(); 29 | initViewPager(); 30 | mImageArray = new int[]{ 31 | R.mipmap.bg_android, 32 | R.mipmap.bg_ios, 33 | R.mipmap.bg_js, 34 | R.mipmap.bg_other}; 35 | mColorArray = new int[]{ 36 | android.R.color.holo_blue_light, 37 | android.R.color.holo_red_light, 38 | android.R.color.holo_orange_light, 39 | android.R.color.holo_green_light}; 40 | 41 | mCoordinatorTabLayout = (CoordinatorTabLayout) findViewById(R.id.coordinatortablayout); 42 | mCoordinatorTabLayout.setTranslucentStatusBar(this) 43 | .setTitle("Demo") 44 | .setBackEnable(true) 45 | .setImageArray(mImageArray, mColorArray) 46 | .setupWithViewPager(mViewPager); 47 | } 48 | 49 | private void initFragments() { 50 | mFragments = new ArrayList<>(); 51 | for (String title : mTitles) { 52 | mFragments.add(MainFragment.getInstance(title)); 53 | } 54 | } 55 | 56 | private void initViewPager() { 57 | mViewPager = (ViewPager) findViewById(R.id.vp); 58 | mViewPager.setOffscreenPageLimit(4); 59 | mViewPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager(), mFragments, mTitles)); 60 | } 61 | 62 | @Override 63 | public boolean onOptionsItemSelected(MenuItem item) { 64 | if (item.getItemId() == android.R.id.home) { 65 | finish(); 66 | } 67 | 68 | switch (item.getItemId()) { 69 | case R.id.action_about: 70 | IntentUtils.openUrl(this, "https://github.com/hugeterry/CoordinatorTabLayout"); 71 | break; 72 | case R.id.action_about_me: 73 | IntentUtils.openUrl(this, "http://hugeterry.cn/about"); 74 | break; 75 | } 76 | return super.onOptionsItemSelected(item); 77 | } 78 | 79 | @Override 80 | public boolean onCreateOptionsMenu(Menu menu) { 81 | getMenuInflater().inflate(R.menu.menu_main, menu); 82 | return super.onCreateOptionsMenu(menu); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /sample/src/main/java/cn/hugeterry/coordinatortablayoutdemo/MainFragment.java: -------------------------------------------------------------------------------- 1 | package cn.hugeterry.coordinatortablayoutdemo; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.support.v7.widget.LinearLayoutManager; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | /** 15 | * Created by hugeterry(http://hugeterry.cn) 16 | */ 17 | public class MainFragment extends Fragment { 18 | private RecyclerView mRecyclerView; 19 | 20 | private List mDatas; 21 | private static final String ARG_TITLE = "title"; 22 | private String mTitle; 23 | 24 | public static MainFragment getInstance(String title) { 25 | MainFragment fra = new MainFragment(); 26 | Bundle bundle = new Bundle(); 27 | bundle.putString(ARG_TITLE, title); 28 | fra.setArguments(bundle); 29 | return fra; 30 | } 31 | 32 | @Override 33 | public void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | Bundle bundle = getArguments(); 36 | mTitle = bundle.getString(ARG_TITLE); 37 | } 38 | 39 | @Override 40 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 41 | View v = inflater.inflate(R.layout.fragment_main, container, false); 42 | 43 | initData(); 44 | mRecyclerView = (RecyclerView) v.findViewById(R.id.recyclerview); 45 | mRecyclerView.setLayoutManager(new LinearLayoutManager(mRecyclerView.getContext())); 46 | mRecyclerView.setAdapter(new RecyclerAdapter(mRecyclerView.getContext(), mDatas)); 47 | 48 | return v; 49 | } 50 | 51 | private void initData() { 52 | mDatas = new ArrayList<>(); 53 | for (int i = 'A'; i < 'z'; i++) { 54 | mDatas.add(mTitle + (char) i); 55 | } 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /sample/src/main/java/cn/hugeterry/coordinatortablayoutdemo/MyPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package cn.hugeterry.coordinatortablayoutdemo; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | import android.support.v4.app.FragmentPagerAdapter; 6 | 7 | import java.util.ArrayList; 8 | 9 | /** 10 | * Created by hugeterry(http://hugeterry.cn) 11 | */ 12 | public class MyPagerAdapter extends FragmentPagerAdapter { 13 | private ArrayList mFragments = new ArrayList<>(); 14 | private final String[] mTitles; 15 | 16 | public MyPagerAdapter(FragmentManager fm, ArrayList mFragments, String[] mTitles) { 17 | super(fm); 18 | this.mFragments = mFragments; 19 | this.mTitles = mTitles; 20 | } 21 | 22 | @Override 23 | public int getCount() { 24 | return mFragments.size(); 25 | } 26 | 27 | @Override 28 | public CharSequence getPageTitle(int position) { 29 | return mTitles[position]; 30 | } 31 | 32 | @Override 33 | public Fragment getItem(int position) { 34 | return mFragments.get(position); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sample/src/main/java/cn/hugeterry/coordinatortablayoutdemo/RecyclerAdapter.java: -------------------------------------------------------------------------------- 1 | package cn.hugeterry.coordinatortablayoutdemo; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.TextView; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * Created by hugeterry(http://hugeterry.cn) 14 | */ 15 | 16 | public class RecyclerAdapter extends RecyclerView.Adapter { 17 | private Context mContext; 18 | private List mDatas; 19 | 20 | public RecyclerAdapter(Context context, List datas) { 21 | mContext = context; 22 | mDatas = datas; 23 | } 24 | 25 | @Override 26 | public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 27 | return new MyViewHolder(LayoutInflater.from( 28 | mContext).inflate(R.layout.item_main, parent, false)); 29 | } 30 | 31 | @Override 32 | public void onBindViewHolder(MyViewHolder holder, int position) { 33 | holder.tv.setText(mDatas.get(position)); 34 | } 35 | 36 | @Override 37 | public int getItemCount() { 38 | return mDatas.size(); 39 | } 40 | 41 | class MyViewHolder extends RecyclerView.ViewHolder { 42 | TextView tv; 43 | 44 | public MyViewHolder(View view) { 45 | super(view); 46 | tv = (TextView) view.findViewById(R.id.tv_num); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/fragment_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | -------------------------------------------------------------------------------- /sample/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 8 | 12 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/bg_android.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hugeterry/CoordinatorTabLayout/c565332bcf9479dace0e0697973722c7f2c78c0f/sample/src/main/res/mipmap-hdpi/bg_android.jpg -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/bg_ios.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hugeterry/CoordinatorTabLayout/c565332bcf9479dace0e0697973722c7f2c78c0f/sample/src/main/res/mipmap-hdpi/bg_ios.jpg -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/bg_js.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hugeterry/CoordinatorTabLayout/c565332bcf9479dace0e0697973722c7f2c78c0f/sample/src/main/res/mipmap-hdpi/bg_js.jpg -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/bg_other.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hugeterry/CoordinatorTabLayout/c565332bcf9479dace0e0697973722c7f2c78c0f/sample/src/main/res/mipmap-hdpi/bg_other.jpg -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hugeterry/CoordinatorTabLayout/c565332bcf9479dace0e0697973722c7f2c78c0f/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hugeterry/CoordinatorTabLayout/c565332bcf9479dace0e0697973722c7f2c78c0f/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hugeterry/CoordinatorTabLayout/c565332bcf9479dace0e0697973722c7f2c78c0f/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hugeterry/CoordinatorTabLayout/c565332bcf9479dace0e0697973722c7f2c78c0f/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hugeterry/CoordinatorTabLayout/c565332bcf9479dace0e0697973722c7f2c78c0f/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CoordinatorTabLayout 3 | 关于该控件 4 | 关于开发者 5 | 6 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sample/src/test/java/cn/hugeterry/coordinatortablayout/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package cn.hugeterry.coordinatortablayout; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':coordinatortablayout' 2 | -------------------------------------------------------------------------------- /showUI/show1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hugeterry/CoordinatorTabLayout/c565332bcf9479dace0e0697973722c7f2c78c0f/showUI/show1.gif -------------------------------------------------------------------------------- /showUI/show2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hugeterry/CoordinatorTabLayout/c565332bcf9479dace0e0697973722c7f2c78c0f/showUI/show2.gif -------------------------------------------------------------------------------- /showUI/show3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hugeterry/CoordinatorTabLayout/c565332bcf9479dace0e0697973722c7f2c78c0f/showUI/show3.gif -------------------------------------------------------------------------------- /showUI/show4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hugeterry/CoordinatorTabLayout/c565332bcf9479dace0e0697973722c7f2c78c0f/showUI/show4.png -------------------------------------------------------------------------------- /showUI/show5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hugeterry/CoordinatorTabLayout/c565332bcf9479dace0e0697973722c7f2c78c0f/showUI/show5.jpg --------------------------------------------------------------------------------