Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hugeterry/coordinatortablayout
Combination of TabLayout and CoordinatorLayout./TabLayout和CoordinatorLayout相结合的折叠控件
https://github.com/hugeterry/coordinatortablayout
android android-library coordinatorlayout tablayout
Last synced: 30 days ago
JSON representation
Combination of TabLayout and CoordinatorLayout./TabLayout和CoordinatorLayout相结合的折叠控件
- Host: GitHub
- URL: https://github.com/hugeterry/coordinatortablayout
- Owner: hugeterry
- License: apache-2.0
- Created: 2017-01-27T13:40:28.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-12-25T03:38:34.000Z (almost 5 years ago)
- Last Synced: 2024-10-14T19:03:42.718Z (30 days ago)
- Topics: android, android-library, coordinatorlayout, tablayout
- Language: Java
- Homepage:
- Size: 11 MB
- Stars: 4,185
- Watchers: 85
- Forks: 585
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# CoordinatorTabLayout
[![License](https://img.shields.io/badge/license-Apache%202.0-green.svg)](https://github.com/hugeterry/CoordinatorTabLayout/blob/master/LICENSE.txt)
[![Download](https://api.bintray.com/packages/hugeterry/CoordinatorTabLayout/CoordinatorTabLayout/images/download.svg) ](https://bintray.com/hugeterry/CoordinatorTabLayout/CoordinatorTabLayout/_latestVersion)[中文版文档](README_CN.md)
CoordinatorTabLayout is a custom composite control that quickly implements the combination of TabLayout and CoordinatorLayout.
Inherited to the CoordinatorLayout, in the following components used CollapsingToolbarLayout contains TabLayout.![show](showUI/show1.gif)
## Usage
### Step 1
Add the following to your build.gradle:
```groovy
dependencies {
compile 'cn.hugeterry.coordinatortablayout:coordinatortablayout:1.2.2'
}
```### Step 2
Config in xml:
```xml
```
### Step 3
![show](showUI/show3.gif)
Use it in your own code:
1.`setTitle(String title)`:Set the CoordinatorTabLayout's title.
2.`setupWithViewPager(ViewPager viewPager)`:To link the two together.
3.`setImageArray(int[] imageArray)`:Set the image array of the header according to the number of tabs and pass it to the control.
```java
//Add the fragment to the viewpager
initFragments();
initViewPager();
//Image array
mImageArray = new int[]{
R.mipmap.bg_android,
R.mipmap.bg_ios,
R.mipmap.bg_js,
R.mipmap.bg_other};mCoordinatorTabLayout = (CoordinatorTabLayout) findViewById(R.id.coordinatortablayout);
mCoordinatorTabLayout.setTitle("Demo")
.setImageArray(mImageArray)
.setupWithViewPager(mViewPager);
```Finish, enjoy it.
## More
### Set the content scrim
![show](showUI/show2.gif)
`setImageArray(int[] imageArray, int[] colorArray)`:Set the color array to use for the content scrim for each tab.
```java
mColorArray = new int[]{
android.R.color.holo_blue_light,
android.R.color.holo_red_light,
android.R.color.holo_orange_light,
android.R.color.holo_green_light};
mCoordinatorTabLayout.setImageArray(mImageArray, mColorArray);
```### Set translucent status bar
![show](showUI/show4.png)
`setTranslucentStatusBar(Activity activity)`:Set translucent status bar,Support android4.4 and above.
```java
mCoordinatorTabLayout.setTranslucentStatusBar(activity);
```### Set translucent navigation bar
![show](showUI/show5.jpg)
`setTranslucentNavigationBar(Activity activity)`:Set translucent navigation bar,Support android4.4 and above.
```java
mCoordinatorTabLayout.setTranslucentNavigationBar(activity);
```### Set back enable
`setBackEnable(Boolean canBack)`:To enable the Up button for an activity that has a parent activity.
```java
@Override
protected void onCreate(Bundle savedInstanceState) {
...
mCoordinatorTabLayout.setBackEnable(true);
...
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
}
return super.onOptionsItemSelected(item);
}
```### Load header images from network
`setLoadHeaderImagesListener(LoadHeaderImagesListener loadHeaderImagesListener)`:Set the listener that gets the header images.
```java
@Override
protected void onCreate(Bundle savedInstanceState) {
...
mCoordinatorTabLayout.setTitle("Demo")
.setBackEnable(true)
.setContentScrimColorArray(mColorArray)
.setLoadHeaderImagesListener(new LoadHeaderImagesListener() {
@Override
public void loadHeaderImages(ImageView imageView, TabLayout.Tab tab) {
switch (tab.getPosition()) {
case 0:
//load header images
break;
...
}
}
})
.setupWithViewPager(mViewPager);
}
```
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)### Set the behavior mode for the Tabs in this layout
`setTabMode(@TabLayout.Mode int mode)`:The valid input options are:MODE_FIXED,MODE_SCROLLABLE
```java
mCoordinatorTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
```### Add a CoordinatorTabLayout.OnTabSelectedListener
`addOnTabSelectedListener(OnTabSelectedListener onTabSelectedListener)`:Add a CoordinatorTabLayout.OnTabSelectedListener that will be invoked when tab selection changes.
```java
mCoordinatorTabLayout.addOnTabSelectedListener(new OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {}
@Override
public void onTabUnselected(TabLayout.Tab tab) {}
@Override
public void onTabReselected(TabLayout.Tab tab) {}
})
```### Gets the child control
`getActionBar()`:get the ActionBar
`getTabLayout()`:get the TabLayout
`getImageView()`:get the ImageView[More code](https://github.com/hugeterry/CoordinatorTabLayout/blob/master/sample/src/main/java/cn/hugeterry/coordinatortablayoutdemo/MainActivity.java)
## Attributes
- `app:contentScrim` -> color.Defaults to ?attr/colorPrimary
- `app:tabIndicatorColor` -> color.
- `app:tabTextColor` -> color.## Demo
[http://fir.im/ctlayout](http://fir.im/ctlayout)## LICENSE
Copyright 2017 HugeTerry.
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 athttp://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.