Repository: ogaclejapan/SmartTabLayout Branch: master Commit: 712e81a92f1e Files: 95 Total size: 171.7 KB Directory structure: gitextract_8nyfmi02/ ├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.txt ├── README.md ├── build.gradle ├── demo/ │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ ├── java/ │ │ └── com/ │ │ └── ogaclejapan/ │ │ └── smarttablayout/ │ │ └── demo/ │ │ ├── Demo.java │ │ ├── DemoActivity.java │ │ ├── DemoFragment.java │ │ ├── DemoLikeMediumActivity.java │ │ ├── DemoRtlActivity.java │ │ ├── DemoTabWithNotificationMarkActivity.java │ │ ├── MainActivity.java │ │ └── TintableImageView.java │ └── res/ │ ├── color/ │ │ ├── custom_tab.xml │ │ ├── custom_tab_icon.xml │ │ └── custom_tab_like_a_medium.xml │ ├── drawable/ │ │ ├── custom_circle.xml │ │ ├── custom_icon.xml │ │ ├── custom_tab.xml │ │ └── shape_notification_mark.xml │ ├── layout/ │ │ ├── activity_demo.xml │ │ ├── activity_demo_tab_with_notification_mark.xml │ │ ├── activity_like_a_medium.xml │ │ ├── activity_main.xml │ │ ├── activity_rtl.xml │ │ ├── custom_tab.xml │ │ ├── custom_tab_circle.xml │ │ ├── custom_tab_icon1.xml │ │ ├── custom_tab_icon2.xml │ │ ├── custom_tab_icon_and_notification_mark.xml │ │ ├── custom_tab_icon_and_text.xml │ │ ├── custom_tab_like_a_medium.xml │ │ ├── custom_tab_margin.xml │ │ ├── demo_always_in_center.xml │ │ ├── demo_basic.xml │ │ ├── demo_basic_title_offset_auto_center.xml │ │ ├── demo_custom_tab_colors.xml │ │ ├── demo_custom_tab_icon_and_notification_mark.xml │ │ ├── demo_custom_tab_icon_and_text.xml │ │ ├── demo_custom_tab_icons1.xml │ │ ├── demo_custom_tab_icons2.xml │ │ ├── demo_custom_tab_margin.xml │ │ ├── demo_custom_tab_text.xml │ │ ├── demo_distribute_evenly.xml │ │ ├── demo_indicator_trick1.xml │ │ ├── demo_indicator_trick2.xml │ │ ├── demo_like_a_medium_tag.xml │ │ ├── demo_rtl.xml │ │ ├── demo_smart_indicator.xml │ │ └── fragment_demo.xml │ ├── menu/ │ │ ├── menu_demo.xml │ │ └── menu_main.xml │ └── values/ │ ├── attrs.xml │ ├── colors.xml │ ├── dimens.xml │ ├── ids.xml │ ├── strings.xml │ └── styles.xml ├── gradle/ │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat ├── library/ │ ├── .gitignore │ ├── LICENSE │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ ├── java/ │ │ └── com/ │ │ └── ogaclejapan/ │ │ └── smarttablayout/ │ │ ├── SmartTabIndicationInterpolator.java │ │ ├── SmartTabLayout.java │ │ ├── SmartTabStrip.java │ │ └── Utils.java │ └── res/ │ └── values/ │ └── attrs.xml ├── publish.gradle ├── settings.gradle └── utils-v4/ ├── .gitignore ├── LICENSE ├── build.gradle ├── proguard-rules.pro └── src/ └── main/ ├── AndroidManifest.xml └── java/ └── com/ └── ogaclejapan/ └── smarttablayout/ └── utils/ ├── PagerItem.java ├── PagerItems.java ├── ViewPagerItem.java ├── ViewPagerItemAdapter.java ├── ViewPagerItems.java └── v4/ ├── Bundler.java ├── FragmentPagerItem.java ├── FragmentPagerItemAdapter.java ├── FragmentPagerItems.java └── FragmentStatePagerItemAdapter.java ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # https://github.com/github/gitignore # https://github.com/hsz/idea-gitignore ### JetBrains template # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm *.iml ## Directory-based project format: .idea/ # if you remove the above rule, at least ignore the following: # User-specific stuff: # .idea/workspace.xml # .idea/tasks.xml # .idea/dictionaries # Sensitive or high-churn files: # .idea/dataSources.ids # .idea/dataSources.xml # .idea/sqlDataSources.xml # .idea/dynamic.xml # .idea/uiDesigner.xml # Gradle: # .idea/gradle.xml # .idea/libraries # Mongo Explorer plugin: # .idea/mongoSettings.xml ## File-based project format: *.ipr *.iws ## Plugin-specific files: # IntelliJ /out/ # mpeltonen/sbt-idea plugin .idea_modules/ # JIRA plugin atlassian-ide-plugin.xml # Crashlytics plugin (for Android Studio and IntelliJ) com_crashlytics_export_strings.xml crashlytics.properties crashlytics-build.properties ### Android template # Built application files *.apk *.ap_ # Files for the Dalvik VM *.dex # Java class files *.class # Generated files bin/ gen/ # Gradle files .gradle/ build/ /*/build/ # Local configuration file (sdk path, etc) local.properties # Proguard folder generated by Eclipse proguard/ # Log Files *.log ================================================ FILE: CHANGELOG.md ================================================ # Version 2.0.0 * Migrate to androidx 1.0.0 * Remove util-v13 library # Version 1.7.0 * Update support library version to 28.0.0 * Change target sdk version to 28 * Change min sdk version to 14 * Deprecated util-v13 library # Version 1.6.1 * Fixed issue with center last item in always in center tablayout #160 # Version 1.6.0 * Add `stl_indicatorWidth` to custom indicator's width #106 # Version 1.5.1 * Fixed indicator position of auto_center #100 # Version 1.5.0 * Add `stl_drawDecorationAfterTab` attribute for change the drawing order #58 * Add `stl_titleOffset` attribute for adjust the slide position #89 * Fixed a condition code of onSizeChanged for always in center # Version 1.4.2 * Change the call order of OnTabClickListener when press the tab #74 # Version 1.4.1 * Update android support library version to 22.2.1 # Version 1.4.0 * Add TabClickListener interface #68 # Version 1.3.0 * RTL support #48 * Add `stl_clickable` attribute. # Version 1.2.3 * Modify to ensure the first scroll #54 # Version 1.2.2 * Fix bug when indicatorAlwaysInCenter is true and tabHost has only two tabs #50 # Version 1.2.1 * Add custom ScrollListener interface #46 # Version 1.2.0 * Support the margin of each tab. * Add `stl_indicatorWithoutPadding` and `stl_indicatorGravity` attributes. * Add `stl_overlineColor` and `stl_overlineThickness` attributes. # Version 1.1.3 * Allow to set the background on default tab #13 # Version 1.1.2 * Added setter for tab text colors #10 * Allow to set a String title dynamically on PagerItems. #7 # Version 1.1.1 * Enable the format of ‘reference’ for defaultTextColor to support ColorStateList #3 # Version 1.1.0 * Supported Icon Tab. #1 # Version 1.0.0 * Initial release. ================================================ FILE: CONTRIBUTING.md ================================================ # Contributing If you would like to contribute code to SmartTabLayout you can do so through GitHub by forking the repository and sending a pull request. When submitting code, please make every effort to follow existing conventions and style in order to keep the code as readable as possible. ## Coding Style * Use the AndroidModernStyle of [Android Code Styles](https://github.com/ogaclejapan/android-code-styles) repository ================================================ FILE: LICENSE.txt ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright (C) 2015 ogaclejapan Copyright (C) 2013 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: README.md ================================================ # SmartTabLayout [![Maven Central][maven_central_badge_svg]][maven_central_badge_app] [![Android Arsenal][android_arsenal_badge_svg]][android_arsenal_badge_link] [![Android Weekly][android_weekly_badge_svg]][android_weekly_badge_link] ![icon][demo_icon] A custom ViewPager title strip which gives continuous feedback to the user when scrolling. This library has been added some features and utilities based on [android-SlidingTabBasic][google_slidingtabbasic] project of Google Samples. ![SmartTabLayout Demo1][demo1_gif] ![SmartTabLayout Demo2][demo2_gif] ![SmartTabLayout Demo3][demo3_gif] ![SmartTabLayout Demo4][demo4_gif] ![SmartTabLayout Demo5][demo5_gif] ![SmartTabLayout Demo6][demo6_gif] ![SmartTabLayout Demo7][demo7_gif] Try out the sample application on the Play Store. [![Get it on Google Play][googleplay_store_badge]][demo_app] # Usage _(For a working implementation of this project see the demo/ folder.)_ Add the dependency to your build.gradle. ``` // For androidx (1.0.0) dependencies { compile 'com.ogaclejapan.smarttablayout:library:2.0.0@aar' //Optional: see how to use the utility. compile 'com.ogaclejapan.smarttablayout:utils-v4:2.0.0@aar' } // For legacy android support library (28.0.0) dependencies { compile 'com.ogaclejapan.smarttablayout:library:1.7.0@aar' //Optional: see how to use the utility. compile 'com.ogaclejapan.smarttablayout:utils-v4:1.7.0@aar' //Deprecated since 1.7.0 compile 'com.ogaclejapan.smarttablayout:utils-v13:1.7.0@aar' } ``` Include the SmartTabLayout widget in your layout. This should usually be placed above the ViewPager it represents. ```xml ``` In your onCreate method (or onCreateView for a fragment), bind the widget to the ViewPager. (If you use a utility together, you can easily add items to PagerAdapter) e.g. ViewPager of v4.Fragment ```java FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter( getSupportFragmentManager(), FragmentPagerItems.with(this) .add(R.string.titleA, PageFragment.class) .add(R.string.titleB, PageFragment.class) .create()); ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); viewPager.setAdapter(adapter); SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab); viewPagerTab.setViewPager(viewPager); ``` (Optional) If you use an OnPageChangeListener with your view pager you should set it in the widget rather than on the pager directly. ```java viewPagerTab.setOnPageChangeListener(mPageChangeListener); ``` (Optional) Using the FragmentPagerItemAdapter of utility, you will be able to get a position in the Fragment side. ```java int position = FragmentPagerItem.getPosition(getArguments()); ``` This position will help to implement the parallax scrolling header that contains the ViewPager :P # Attributes There are several attributes you can set: | attr | description | |:---|:---| | stl_indicatorAlwaysInCenter | If set to true, active tab is always displayed in center (Like Newsstand google app), default false | | stl_indicatorWithoutPadding | If set to true, draw the indicator without padding of tab, default false | | stl_indicatorInFront | Draw the indicator in front of the underline, default false | | stl_indicatorInterpolation | Behavior of the indicator: 'linear' or 'smart' | | stl_indicatorGravity | Drawing position of the indicator: 'bottom' or 'top' or 'center', default 'bottom' | | stl_indicatorColor | Color of the indicator | | stl_indicatorColors | Multiple colors of the indicator, can set the color for each tab | | stl_indicatorThickness | Thickness of the indicator | | stl_indicatorWidth | Width of the indicator, default 'auto' | | stl_indicatorCornerRadius | Radius of rounded corner the indicator | | stl_overlineColor | Color of the top line | | stl_overlineThickness | Thickness of the top line | | stl_underlineColor | Color of the bottom line | | stl_underlineThickness | Thickness of the bottom line | | stl_dividerColor | Color of the dividers between tabs | | stl_dividerColors | Multiple colors of the dividers between tabs, can set the color for each tab | | stl_dividerThickness | Thickness of the divider | | stl_defaultTabBackground | Background drawable of each tab. In general it set the StateListDrawable | | stl_defaultTabTextAllCaps | If set to true, all tab titles will be upper case, default true | | stl_defaultTabTextColor | Text color of the tab that was included by default | | stl_defaultTabTextSize | Text size of the tab that was included by default | | stl_defaultTabTextHorizontalPadding | Text layout padding of the tab that was included by default | | stl_defaultTabTextMinWidth | Minimum width of tab | | stl_customTabTextLayoutId | Layout ID defined custom tab. If you do not specify a layout, use the default tab | | stl_customTabTextViewId | Text view ID in a custom tab layout. If you do not define with customTabTextLayoutId, does not work | | stl_distributeEvenly | If set to true, each tab is given the same weight, default false | | stl_clickable | If set to false, disable the selection of a tab click, default true | | stl_titleOffset | If set to 'auto_center', the slide position of the tab in the middle it will keep to the center. If specify a dimension it will be offset from the left edge, default 24dp | | stl_drawDecorationAfterTab | Draw the decoration(indicator and lines) after drawing of tab, default false | *__Notes:__ Both 'stl_indicatorAlwaysInCenter' and 'stl_distributeEvenly' if it is set to true, it will throw UnsupportedOperationException.* # How to customize the tab The customization of tab There are three ways. * Customize the attribute * SmartTabLayout#setCustomTabView(int layoutResId, int textViewId) * SmartTabLayout#setCustomTabView(TabProvider provider) If set the TabProvider, can build a view for each tab. ```java public class SmartTabLayout extends HorizontalScrollView { //... /** * Create the custom tabs in the tab layout. Set with * {@link #setCustomTabView(com.ogaclejapan.smarttablayout.SmartTabLayout.TabProvider)} */ public interface TabProvider { /** * @return Return the View of {@code position} for the Tabs */ View createTabView(ViewGroup container, int position, PagerAdapter adapter); } //... } ``` # How to use the utility Utility has two types available to suit the Android support library. * utils-v4 library contains the PagerAdapter implementation class for _androidx.fragment.app.Fragment_ * (Deprecated) utils-v13 library contains the PagerAdapter implementation class for _android.app.Fragment_ The two libraries have different Android support libraries that depend, but implemented functionality is the same. ## PagerAdapter for View-based Page ```java ViewPagerItemAdapter adapter = new ViewPagerItemAdapter(ViewPagerItems.with(this) .add(R.string.title, R.layout.page) .add("title", R.layout.page) .create()); viewPager.setAdapter(adapter); //... public void onPageSelected(int position) { //.instantiateItem() from until .destroyItem() is called it will be able to get the View of page. View page = adapter.getPage(position); } ``` ## PagerAdapter for Fragment-based Page Fragment-based PagerAdapter There are two implementations. Please differences refer to the library documentation for Android. * FragmentPagerItemAdapter extends FragmentPagerAdapter * FragmentStatePagerItemAdapter extends FragmentStatePagerAdapter ```java FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter( getSupportFragmentManager(), FragmentPagerItems.with(this) .add(R.string.title, PageFragment.class), .add(R.string.title, WithArgumentsPageFragment.class, new Bundler().putString("key", "value").get()), .add("title", PageFragment.class) .create()); viewPager.setAdapter(adapter); //... public void onPageSelected(int position) { //.instantiateItem() from until .destoryItem() is called it will be able to get the Fragment of page. Fragment page = adapter.getPage(position); } ``` *__Notes:__ If using fragment inside a ViewPager, Must be use [Fragment#getChildFragmentManager()](https://developer.android.com/reference/androidx/fragment/app/Fragment.html#getChildFragmentManager).* # Looking for iOS ? Check [WormTabStrip](https://github.com/EzimetYusup/WormTabStrip) out. # LICENSE ``` Copyright (C) 2015 ogaclejapan Copyright (C) 2013 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ``` [demo1_gif]: https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/master/art/demo1.gif [demo2_gif]: https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/master/art/demo2.gif [demo3_gif]: https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/master/art/demo3.gif [demo4_gif]: https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/master/art/demo4.gif [demo5_gif]: https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/master/art/demo5.gif [demo6_gif]: https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/master/art/demo6.gif [demo7_gif]: https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/master/art/demo7.gif [demo_app]: https://play.google.com/store/apps/details?id=com.ogaclejapan.smarttablayout.demo&referrer=utm_source%3Dgithub [demo_icon]: https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/master/art/icon.png [googleplay_store_badge]: http://www.android.com/images/brand/get_it_on_play_logo_large.png [maven_central_badge_svg]: https://maven-badges.herokuapp.com/maven-central/com.ogaclejapan.smarttablayout/library/badge.svg?style=flat [maven_central_badge_app]: https://maven-badges.herokuapp.com/maven-central/com.ogaclejapan.smarttablayout/library [android_arsenal_badge_svg]: https://img.shields.io/badge/Android%20Arsenal-SmartTabLayout-brightgreen.svg?style=flat [android_arsenal_badge_link]: http://android-arsenal.com/details/1/1683 [android_weekly_badge_svg]: https://img.shields.io/badge/AndroidWeekly-%23148-blue.svg [android_weekly_badge_link]: http://androidweekly.net/issues/issue-148 [qiitanium]: https://github.com/ogaclejapan/Qiitanium [google_slidingtabbasic]: https://github.com/googlesamples/android-SlidingTabsBasic ================================================ FILE: build.gradle ================================================ // Top-level build file where you can add configuration options common to all sub-projects/modules. ext { // Package information for bintray pkginfo = [name : ARTIFACT_NAME, description: ARTIFACT_DESCRIPTION, site : SITE_URL, issue : ISSUE_URL, vcs : SCM_URL] } buildscript { repositories { google() mavenCentral() maven { url "https://plugins.gradle.org/m2/" } jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.3.1' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' classpath 'com.github.ben-manes:gradle-versions-plugin:0.21.0' classpath 'gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin:0.15.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { version = VERSION_NAME group = GROUP repositories { google() mavenCentral() jcenter() } } task clean(type: Delete) { delete rootProject.buildDir } ================================================ FILE: demo/.gitignore ================================================ /build ================================================ FILE: demo/build.gradle ================================================ apply plugin: 'com.android.application' android { compileSdkVersion COMPILE_SDK_VERSION as int defaultConfig { minSdkVersion 14 targetSdkVersion COMPILE_SDK_VERSION as int versionCode VERSION_CODE as int versionName VERSION_NAME } def secretFile = file("${rootDir}/secret.gradle") if (secretFile.exists()) { apply from: secretFile.absolutePath signingConfigs { release { storeFile project.ext.storeFile storePassword project.ext.storePassword keyAlias project.ext.keyAlias keyPassword project.ext.keyPassword } } } buildTypes { release { if (secretFile.exists()) { signingConfig signingConfigs.release } minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { implementation project(':library') implementation project(':utils-v4') implementation "androidx.appcompat:appcompat:${ANDROIDX_APPCOMPAT_VERSION}" } ================================================ FILE: demo/proguard-rules.pro ================================================ # Add project specific ProGuard rules here. # By default, the flags in this file are appended to flags specified # in /Users/msk/Library/Android/sdk/tools/proguard/proguard-android.txt # You can edit the include path and order by changing the proguardFiles # directive in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # Add any project specific keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} ================================================ FILE: demo/src/main/AndroidManifest.xml ================================================ ================================================ FILE: demo/src/main/java/com/ogaclejapan/smarttablayout/demo/Demo.java ================================================ package com.ogaclejapan.smarttablayout.demo; import android.content.Context; import android.content.res.Resources; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import com.ogaclejapan.smarttablayout.SmartTabLayout; import androidx.viewpager.widget.PagerAdapter; public enum Demo { BASIC(R.string.demo_title_basic, R.layout.demo_basic), BASIC2(R.string.demo_title_basic2, R.layout.demo_basic_title_offset_auto_center), SMART_INDICATOR(R.string.demo_title_smart_indicator, R.layout.demo_smart_indicator), DISTRIBUTE_EVENLY(R.string.demo_title_distribute_evenly, R.layout.demo_distribute_evenly) { @Override public int[] tabs() { return tab3(); } }, ALWAYS_IN_CENTER(R.string.demo_title_always_in_center, R.layout.demo_always_in_center), CUSTOM_TAB(R.string.demo_title_custom_tab_text, R.layout.demo_custom_tab_text), CUSTOM_TAB_COLORS(R.string.demo_title_custom_tab_colors, R.layout.demo_custom_tab_colors), CUSTOM_TAB_ICONS1(R.string.demo_title_custom_tab_icons1, R.layout.demo_custom_tab_icons1) { @Override public int[] tabs() { return new int[] { R.string.demo_tab_no_title, R.string.demo_tab_no_title, R.string.demo_tab_no_title, R.string.demo_tab_no_title }; } @Override public void setup(SmartTabLayout layout) { super.setup(layout); final LayoutInflater inflater = LayoutInflater.from(layout.getContext()); final Resources res = layout.getContext().getResources(); layout.setCustomTabView(new SmartTabLayout.TabProvider() { @Override public View createTabView(ViewGroup container, int position, PagerAdapter adapter) { ImageView icon = (ImageView) inflater.inflate(R.layout.custom_tab_icon1, container, false); switch (position) { case 0: icon.setImageDrawable(res.getDrawable(R.drawable.ic_home_white_24dp)); break; case 1: icon.setImageDrawable(res.getDrawable(R.drawable.ic_search_white_24dp)); break; case 2: icon.setImageDrawable(res.getDrawable(R.drawable.ic_person_white_24dp)); break; case 3: icon.setImageDrawable(res.getDrawable(R.drawable.ic_flash_on_white_24dp)); break; default: throw new IllegalStateException("Invalid position: " + position); } return icon; } }); } }, CUSTOM_TAB_ICONS2(R.string.demo_title_custom_tab_icons2, R.layout.demo_custom_tab_icons2) { @Override public int[] tabs() { return new int[] { R.string.demo_tab_no_title, R.string.demo_tab_no_title, R.string.demo_tab_no_title, R.string.demo_tab_no_title }; } @Override public void setup(SmartTabLayout layout) { super.setup(layout); final LayoutInflater inflater = LayoutInflater.from(layout.getContext()); final Resources res = layout.getContext().getResources(); layout.setCustomTabView(new SmartTabLayout.TabProvider() { @Override public View createTabView(ViewGroup container, int position, PagerAdapter adapter) { ImageView icon = (ImageView) inflater.inflate(R.layout.custom_tab_icon2, container, false); switch (position) { case 0: icon.setImageDrawable(res.getDrawable(R.drawable.ic_home_white_24dp)); break; case 1: icon.setImageDrawable(res.getDrawable(R.drawable.ic_search_white_24dp)); break; case 2: icon.setImageDrawable(res.getDrawable(R.drawable.ic_person_white_24dp)); break; case 3: icon.setImageDrawable(res.getDrawable(R.drawable.ic_flash_on_white_24dp)); break; default: throw new IllegalStateException("Invalid position: " + position); } return icon; } }); } }, CUSTOM_TAB_ICON_AND_TEXT(R.string.demo_title_custom_tab_icon_and_text, R.layout.demo_custom_tab_icon_and_text) { @Override public int[] tabs() { return tab3(); } }, CUSTOM_TAB_ICON_AND_NOTIFICATION_MARK(R.string.demo_title_custom_tab_icon_and_notification_mark, R.layout.demo_custom_tab_icon_and_notification_mark) { @Override public int[] tabs() { return tab3(); } @Override public void startActivity(Context context) { DemoTabWithNotificationMarkActivity.startActivity(context, this); } }, CUSTOM_TAB_MARGIN(R.string.demo_title_custom_tab_margin, R.layout.demo_custom_tab_margin), INDICATOR_TRICK1(R.string.demo_title_indicator_trick1, R.layout.demo_indicator_trick1), INDICATOR_TRICK2(R.string.demo_title_indicator_trick2, R.layout.demo_indicator_trick2), RIGHT_TO_LEFT(R.string.demo_title_right_to_left, R.layout.demo_rtl) { @Override public void startActivity(Context context) { DemoRtlActivity.startActivity(context, this); } }, LIKE_MEDIUM_TAG(R.string.demo_title_advanced_medium, R.layout.demo_like_a_medium_tag) { @Override public int[] tabs() { return new int[] { R.string.demo_tab_like_a_medium_top, R.string.demo_tab_like_a_medium_latest }; } @Override public void startActivity(Context context) { DemoLikeMediumActivity.startActivity(context, this); } }; public final int titleResId; public final int layoutResId; Demo(int titleResId, int layoutResId) { this.titleResId = titleResId; this.layoutResId = layoutResId; } public static int[] tab10() { return new int[] { R.string.demo_tab_1, R.string.demo_tab_2, R.string.demo_tab_3, R.string.demo_tab_4, R.string.demo_tab_5, R.string.demo_tab_6, R.string.demo_tab_7, R.string.demo_tab_8, R.string.demo_tab_9, R.string.demo_tab_10 }; } public static int[] tab3() { return new int[] { R.string.demo_tab_8, R.string.demo_tab_9, R.string.demo_tab_10 }; } public void startActivity(Context context) { DemoActivity.startActivity(context, this); } public void setup(final SmartTabLayout layout) { //Do nothing. } public int[] tabs() { return tab10(); } } ================================================ FILE: demo/src/main/java/com/ogaclejapan/smarttablayout/demo/DemoActivity.java ================================================ package com.ogaclejapan.smarttablayout.demo; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.ViewGroup; import com.ogaclejapan.smarttablayout.SmartTabLayout; import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItem; import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter; import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.viewpager.widget.ViewPager; public class DemoActivity extends AppCompatActivity { private static final String KEY_DEMO = "demo"; public static void startActivity(Context context, Demo demo) { Intent intent = new Intent(context, DemoActivity.class); intent.putExtra(KEY_DEMO, demo.name()); context.startActivity(intent); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_demo); Demo demo = getDemo(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(demo.titleResId); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); ViewGroup tab = (ViewGroup) findViewById(R.id.tab); tab.addView(LayoutInflater.from(this).inflate(demo.layoutResId, tab, false)); ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab); demo.setup(viewPagerTab); FragmentPagerItems pages = new FragmentPagerItems(this); for (int titleResId : demo.tabs()) { pages.add(FragmentPagerItem.of(getString(titleResId), DemoFragment.class)); } FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter( getSupportFragmentManager(), pages); viewPager.setAdapter(adapter); viewPagerTab.setViewPager(viewPager); } private Demo getDemo() { return Demo.valueOf(getIntent().getStringExtra(KEY_DEMO)); } } ================================================ FILE: demo/src/main/java/com/ogaclejapan/smarttablayout/demo/DemoFragment.java ================================================ package com.ogaclejapan.smarttablayout.demo; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItem; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; public class DemoFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_demo, container, false); } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); int position = FragmentPagerItem.getPosition(getArguments()); TextView title = (TextView) view.findViewById(R.id.item_title); title.setText(String.valueOf(position)); } } ================================================ FILE: demo/src/main/java/com/ogaclejapan/smarttablayout/demo/DemoLikeMediumActivity.java ================================================ package com.ogaclejapan.smarttablayout.demo; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.ViewGroup; import com.ogaclejapan.smarttablayout.SmartTabLayout; import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItem; import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter; import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.viewpager.widget.ViewPager; public class DemoLikeMediumActivity extends AppCompatActivity { private static final String KEY_DEMO = "demo"; public static void startActivity(Context context, Demo demo) { Intent intent = new Intent(context, DemoLikeMediumActivity.class); intent.putExtra(KEY_DEMO, demo.name()); context.startActivity(intent); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_like_a_medium); Demo demo = getDemo(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(demo.titleResId); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); ViewGroup tab = (ViewGroup) findViewById(R.id.tab); tab.addView(LayoutInflater.from(this).inflate(demo.layoutResId, tab, false)); ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab); demo.setup(viewPagerTab); FragmentPagerItems pages = new FragmentPagerItems(this); for (int titleResId : demo.tabs()) { pages.add(FragmentPagerItem.of(getString(titleResId), DemoFragment.class)); } FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter( getSupportFragmentManager(), pages); viewPager.setAdapter(adapter); viewPagerTab.setViewPager(viewPager); } private Demo getDemo() { return Demo.valueOf(getIntent().getStringExtra(KEY_DEMO)); } } ================================================ FILE: demo/src/main/java/com/ogaclejapan/smarttablayout/demo/DemoRtlActivity.java ================================================ package com.ogaclejapan.smarttablayout.demo; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.ViewGroup; import com.ogaclejapan.smarttablayout.SmartTabLayout; import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItem; import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter; import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.viewpager.widget.ViewPager; public class DemoRtlActivity extends AppCompatActivity { private static final String KEY_DEMO = "demo"; public static void startActivity(Context context, Demo demo) { Intent intent = new Intent(context, DemoRtlActivity.class); intent.putExtra(KEY_DEMO, demo.name()); context.startActivity(intent); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_rtl); Demo demo = getDemo(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(demo.titleResId); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); ViewGroup tab = (ViewGroup) findViewById(R.id.tab); tab.addView(LayoutInflater.from(this).inflate(demo.layoutResId, tab, false)); ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); final SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab); demo.setup(viewPagerTab); FragmentPagerItems pages = new FragmentPagerItems(this); for (int titleResId : demo.tabs()) { pages.add(FragmentPagerItem.of(getString(titleResId), DemoFragment.class)); } FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter( getSupportFragmentManager(), pages); viewPager.setAdapter(adapter); viewPagerTab.setViewPager(viewPager); } private Demo getDemo() { return Demo.valueOf(getIntent().getStringExtra(KEY_DEMO)); } } ================================================ FILE: demo/src/main/java/com/ogaclejapan/smarttablayout/demo/DemoTabWithNotificationMarkActivity.java ================================================ package com.ogaclejapan.smarttablayout.demo; import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import com.ogaclejapan.smarttablayout.SmartTabLayout; import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItem; import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter; import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems; import java.util.Random; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.ViewPager; public class DemoTabWithNotificationMarkActivity extends AppCompatActivity implements SmartTabLayout.TabProvider { private static final String KEY_DEMO = "demo"; public static void startActivity(Context context, Demo demo) { Intent intent = new Intent(context, DemoTabWithNotificationMarkActivity.class); intent.putExtra(KEY_DEMO, demo.name()); context.startActivity(intent); } private Random random = new Random(System.currentTimeMillis()); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_demo_tab_with_notification_mark); final Demo demo = getDemo(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(demo.titleResId); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); ViewGroup tab = (ViewGroup) findViewById(R.id.tab); tab.addView(LayoutInflater.from(this).inflate(demo.layoutResId, tab, false)); ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); final SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab); viewPagerTab.setCustomTabView(this); FragmentPagerItems pages = new FragmentPagerItems(this); for (int titleResId : demo.tabs()) { pages.add(FragmentPagerItem.of(getString(titleResId), DemoFragment.class)); } FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter( getSupportFragmentManager(), pages); viewPager.setAdapter(adapter); viewPagerTab.setViewPager(viewPager); viewPagerTab.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { super.onPageSelected(position); View tab = viewPagerTab.getTabAt(position); View mark = tab.findViewById(R.id.custom_tab_notification_mark); mark.setVisibility(View.GONE); } }); findViewById(R.id.test).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int position = Math.abs(random.nextInt()) % demo.tabs().length; View tab = viewPagerTab.getTabAt(position); View mark = tab.findViewById(R.id.custom_tab_notification_mark); mark.setVisibility(View.VISIBLE); } }); } @Override public View createTabView(ViewGroup container, int position, PagerAdapter adapter) { LayoutInflater inflater = LayoutInflater.from(container.getContext()); Resources res = container.getContext().getResources(); View tab = inflater.inflate(R.layout.custom_tab_icon_and_notification_mark, container, false); View mark = tab.findViewById(R.id.custom_tab_notification_mark); mark.setVisibility(View.GONE); ImageView icon = (ImageView) tab.findViewById(R.id.custom_tab_icon); switch (position) { case 0: icon.setImageDrawable(res.getDrawable(R.drawable.ic_home_white_24dp)); break; case 1: icon.setImageDrawable(res.getDrawable(R.drawable.ic_search_white_24dp)); break; case 2: icon.setImageDrawable(res.getDrawable(R.drawable.ic_person_white_24dp)); break; default: throw new IllegalStateException("Invalid position: " + position); } return tab; } private Demo getDemo() { return Demo.valueOf(getIntent().getStringExtra(KEY_DEMO)); } } ================================================ FILE: demo/src/main/java/com/ogaclejapan/smarttablayout/demo/MainActivity.java ================================================ package com.ogaclejapan.smarttablayout.demo; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity implements AbsListView.OnItemClickListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView listView = (ListView) findViewById(R.id.list); listView.setOnItemClickListener(this); ArrayAdapter demoAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1); for (Demo demo : Demo.values()) { demoAdapter.add(getString(demo.titleResId)); } listView.setAdapter(demoAdapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_github: openGitHub(); return true; default: return super.onOptionsItemSelected(item); } } @Override public void onItemClick(AdapterView parent, View view, int position, long id) { Demo demo = Demo.values()[position]; demo.startActivity(this); } private void openGitHub() { Uri uri = Uri.parse(getString(R.string.app_github_url)); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } } ================================================ FILE: demo/src/main/java/com/ogaclejapan/smarttablayout/demo/TintableImageView.java ================================================ package com.ogaclejapan.smarttablayout.demo; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.TypedArray; import android.util.AttributeSet; import androidx.appcompat.widget.AppCompatImageView; /** * https://gist.github.com/tylerchesley/5d15d859be4f3ce31213 */ public class TintableImageView extends AppCompatImageView { private ColorStateList tint; public TintableImageView(Context context) { super(context); } public TintableImageView(Context context, AttributeSet attrs) { super(context, attrs); init(context, attrs, 0); } public TintableImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(context, attrs, defStyle); } private void init(Context context, AttributeSet attrs, int defStyle) { TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.TintableImageView, defStyle, 0); tint = a.getColorStateList( R.styleable.TintableImageView_tint); a.recycle(); } @Override protected void drawableStateChanged() { super.drawableStateChanged(); if (tint != null && tint.isStateful()) { updateTintColor(); } } public void setColorFilter(ColorStateList tint) { this.tint = tint; super.setColorFilter(tint.getColorForState(getDrawableState(), 0)); } private void updateTintColor() { int color = tint.getColorForState(getDrawableState(), 0); setColorFilter(color); } } ================================================ FILE: demo/src/main/res/color/custom_tab.xml ================================================ ================================================ FILE: demo/src/main/res/color/custom_tab_icon.xml ================================================ ================================================ FILE: demo/src/main/res/color/custom_tab_like_a_medium.xml ================================================ ================================================ FILE: demo/src/main/res/drawable/custom_circle.xml ================================================ ================================================ FILE: demo/src/main/res/drawable/custom_icon.xml ================================================ ================================================ FILE: demo/src/main/res/drawable/custom_tab.xml ================================================ ================================================ FILE: demo/src/main/res/drawable/shape_notification_mark.xml ================================================ ================================================ FILE: demo/src/main/res/layout/activity_demo.xml ================================================ ================================================ FILE: demo/src/main/res/layout/activity_demo_tab_with_notification_mark.xml ================================================