├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── dalong │ │ └── bottomtabdemo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── dalong │ │ │ └── bottomtabdemo │ │ │ └── MainActivity.java │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ ├── tabbar_discover.png │ │ ├── tabbar_discover_highlighted.png │ │ ├── tabbar_home.png │ │ ├── tabbar_home_highlighted.png │ │ ├── tabbar_message_center.png │ │ ├── tabbar_message_center_highlighted.png │ │ ├── tabbar_more.png │ │ ├── tabbar_more_highlighted.png │ │ ├── tabbar_profile.png │ │ └── tabbar_profile_highlighted.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── dalong │ └── bottomtabdemo │ └── ExampleUnitTest.java ├── build.gradle ├── buttomtablayout ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── dalong │ │ └── buttomtablayout │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── dalong │ │ │ └── buttomtablayout │ │ │ ├── BottomTab.java │ │ │ └── BottomTabLayout.java │ └── res │ │ ├── drawable │ │ └── tab_num_view.xml │ │ ├── layout │ │ └── view_bottom_tab.xml │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── dalong │ └── buttomtablayout │ └── ExampleUnitTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── img └── bottomtab.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | $USER_HOME$/.subversion 48 | 49 | 50 | 51 | 52 | 53 | 1.8 54 | 55 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BottomTabDemo 2 | app底部切换tab控件,本代码加载网络图片使用开源glide框架。 3 | 4 | #效果图 5 | 6 | ![image](https://github.com/dalong982242260/BottomTabDemo/blob/master/img/bottomtab.gif?raw=true) 7 | 8 | #优点 9 | 1、动态设置tab,方便易用 10 | 2、可以加载网络icon 11 | 3、可以设置消息数量 12 | 13 | #使用 14 | 15 | xml: 16 | 17 | 22 | 23 | 24 | java: 25 | 26 | mBottomTabLayout=(BottomTabLayout)findViewById(R.id.mBottomTabLayout); 27 | mBottomTabLayout.setOnTabChangeListener(new BottomTabLayout.OnTabChangeListener() { 28 | @Override 29 | public void onTabSelect(int position) { 30 | Toast.makeText(MainActivity.this, "您选择了"+position, Toast.LENGTH_SHORT).show(); 31 | } 32 | 33 | @Override 34 | public void onTabSelected(int position) { 35 | Toast.makeText(MainActivity.this, "您已经选择了"+position, Toast.LENGTH_SHORT).show(); 36 | } 37 | }); 38 | 39 | mBottomTabLayout.setBottomTabNum(new Random().nextInt(4),new Random().nextInt(100));//设置对应index的小红点数量 40 | 41 | mBottomTabLayout.clearAllBottomTabNum();//清除所有的小红点 42 | 43 | 44 | #感谢 45 | [glide](https://github.com/bumptech/glide) -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "24.0.0" 6 | defaultConfig { 7 | applicationId "com.dalong.bottomtabdemo" 8 | minSdkVersion 14 9 | targetSdkVersion 24 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(include: ['*.jar'], dir: 'libs') 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:24.0.0' 28 | testCompile 'junit:junit:4.12' 29 | compile project(':buttomtablayout') 30 | } 31 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /android/tools/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/dalong/bottomtabdemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.dalong.bottomtabdemo; 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("com.dalong.bottomtabdemo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/dalong/bottomtabdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.dalong.bottomtabdemo; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.util.Log; 6 | import android.view.View; 7 | 8 | import com.dalong.buttomtablayout.BottomTab; 9 | import com.dalong.buttomtablayout.BottomTabLayout; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | import java.util.Random; 14 | 15 | /** 16 | * Android官方底部Tab栏设计规范 17 | * 18 | * 1、推荐底部可以放置3到5个。 19 | * 2、推荐选中的图标或者文字为APP的主色调,如果Tab栏本身就是彩色,推荐黑色和白色作为图标或者文字 20 | * 3、选中的Tab同时显示icon和text。 21 | * 如果只有三个Tab,无论选中未选中,一直显示icon和文字。 22 | * 如果有四到五个Tab,选中的Tab显示文字和icon,未选中的Tab只显示icon 23 | * 4、文字要求言简意赅 24 | * 5、Bottom navigation bars的高度推荐为56dp,icon的尺寸为24*24,这种Google一般推荐使用8的倍数。选中tab的字体大小为14sp,未选中为12sp 25 | * 26 | * Created by zhouweilong on 2016/11/10. 27 | */ 28 | public class MainActivity extends AppCompatActivity { 29 | 30 | public final String TAG=MainActivity.class.getSimpleName(); 31 | 32 | private String[] mTabNames = {"首页", "消息", "搜索", "我的"}; 33 | 34 | /** 35 | * 默认状态下的本地图片 36 | */ 37 | private int[] mUnSelectIcons = { 38 | R.mipmap.tabbar_home, 39 | R.mipmap.tabbar_message_center, 40 | R.mipmap.tabbar_discover, 41 | R.mipmap.tabbar_profile}; 42 | 43 | /** 44 | * 默认状态下的本地图片 45 | */ 46 | private int[] mSelectIcons = { 47 | R.mipmap.tabbar_home_highlighted, 48 | R.mipmap.tabbar_message_center_highlighted, 49 | R.mipmap.tabbar_discover_highlighted, 50 | R.mipmap.tabbar_profile_highlighted}; 51 | 52 | /** 53 | * 默认状态下的网络图片 54 | */ 55 | private String[] mUnSelectUrls={ 56 | "http://www.androidstudy.cn/img/tabbar_home.png", 57 | "http://www.androidstudy.cn/img/tabbar_message_center.png", 58 | "http://www.androidstudy.cn/img/tabbar_discover.png", 59 | "http://www.androidstudy.cn/img/tabbar_profile.png"}; 60 | 61 | /** 62 | * 选中状态下的网络图片 63 | */ 64 | private String[] mSelectUrls={ 65 | "http://www.androidstudy.cn/img/tabbar_home_selected.png", 66 | "http://www.androidstudy.cn/img/tabbar_message_center_highlighted.png", 67 | "http://www.androidstudy.cn/img/tabbar_discover_highlighted.png", 68 | "http://www.androidstudy.cn/img/tabbar_profile_highlighted.png"}; 69 | 70 | 71 | /** 72 | * 未选中的颜色 73 | */ 74 | private int mUnSelectColor = R.color.unSelectColor; 75 | 76 | /** 77 | * 选中的颜色 78 | */ 79 | private int mSelectColor = R.color.SelectColor; 80 | 81 | //底部控件 82 | private BottomTabLayout mBottomTabLayout; 83 | //tab数据 84 | private List mBottomTabs = new ArrayList<>(); 85 | 86 | @Override 87 | protected void onCreate(Bundle savedInstanceState) { 88 | super.onCreate(savedInstanceState); 89 | setContentView(R.layout.activity_main); 90 | initView(); 91 | } 92 | 93 | private void initView() { 94 | mBottomTabLayout=(BottomTabLayout)findViewById(R.id.mBottomTabLayout); 95 | mBottomTabLayout.setOnTabChangeListener(new BottomTabLayout.OnTabChangeListener() { 96 | @Override 97 | public void onTabSelect(int position) { 98 | Log.v(TAG, "您选择了"+position); 99 | } 100 | 101 | @Override 102 | public void onTabSelected(int position) { 103 | Log.v(TAG, "您已经选择了"+position); 104 | } 105 | }); 106 | } 107 | 108 | /** 109 | * 初始化数据 110 | * @param isUrl 111 | */ 112 | private void initData(boolean isUrl) { 113 | mBottomTabs.clear(); 114 | for (int i=0;i 2 | 9 | 10 | 18 | 19 |