FlycoTabLayout 开源项目教程
FlycoTabLayoutAn Android TabLayout Lib项目地址:https://gitcode.com/gh_mirrors/fl/FlycoTabLayout
1、项目的目录结构及介绍
FlycoTabLayout 项目的目录结构如下:
FlycoTabLayout/
├── app/
│ ├── build.gradle
│ ├── src/
│ │ └── main/
│ │ ├── java/
│ │ │ └── com.flyco.tablayout.demo/
│ │ │ └── MainActivity.java
│ │ └── res/
│ │ ├── layout/
│ │ │ └── activity_main.xml
│ │ └── values/
│ │ └── strings.xml
├── library/
│ ├── build.gradle
│ ├── src/
│ │ └── main/
│ │ ├── java/
│ │ │ └── com.flyco.tablayout/
│ │ │ ├── CommonTabLayout.java
│ │ │ ├── SegmentTabLayout.java
│ │ │ ├── SlidingTabLayout.java
│ │ │ └── listener/
│ │ │ └── CustomTabEntity.java
│ │ └── res/
│ │ ├── drawable/
│ │ ├── layout/
│ │ └── values/
│ │ └── attrs.xml
├── build.gradle
├── gradle.properties
├── settings.gradle
└── README.md
目录结构介绍
app/
:包含示例应用的代码和资源文件。build.gradle
:示例应用的构建配置文件。src/main/java/com.flyco.tablayout.demo/
:示例应用的Java代码。src/main/res/
:示例应用的资源文件。
library/
:包含FlycoTabLayout库的代码和资源文件。build.gradle
:库的构建配置文件。src/main/java/com.flyco.tablayout/
:库的Java代码。src/main/res/
:库的资源文件。
build.gradle
:项目的根构建配置文件。gradle.properties
:Gradle属性配置文件。settings.gradle
:项目设置文件。README.md
:项目说明文档。
2、项目的启动文件介绍
项目的启动文件是 app/src/main/java/com.flyco.tablayout.demo/MainActivity.java
。
MainActivity.java
package com.flyco.tablayout.demo;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private String[] mTitles = {"首页", "消息", "联系人", "更多"};
private int[] mIconUnselectIds = {
R.drawable.ic_home_normal, R.drawable.ic_message_normal,
R.drawable.ic_contact_normal, R.drawable.ic_more_normal};
private int[] mIconSelectIds = {
R.drawable.ic_home_selected, R.drawable.ic_message_selected,
R.drawable.ic_contact_selected, R.drawable.ic_more_selected};
private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for (int i = 0; i < mTitles.length; i++) {
mTabEntities.add(new TabEntity(mTitles[i], mIconSelectIds[i], mIconUnselectIds[i]));
}
CommonTabLayout tabLayout = findViewById(R.id.tab_layout);
tabLayout.setTabData(mTabEntities);
tabLayout.setOnTabSelectListener(new OnTabSelectListener() {
@Override
public void onTabSelect(int position) {
Toast.makeText(MainActivity.
FlycoTabLayoutAn Android TabLayout Lib项目地址:https://gitcode.com/gh_mirrors/fl/FlycoTabLayout