├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── markdown-navigator │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── heima │ │ └── tabview │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── heima │ │ │ └── tabview │ │ │ ├── CustomInJavaActivity.java │ │ │ ├── CustomInXmlActivity.java │ │ │ ├── FragmentCommon.java │ │ │ ├── FragmentSample.java │ │ │ ├── MainActivity.java │ │ │ ├── QuickStartActivity.java │ │ │ └── UseInFragment.java │ └── res │ │ ├── drawable-hdpi │ │ ├── tab01_sel.png │ │ ├── tab01_unsel.png │ │ ├── tab02_sel.png │ │ ├── tab02_unsel.png │ │ ├── tab03_sel.png │ │ ├── tab03_unsel.png │ │ ├── tab04_sel.png │ │ ├── tab04_unsel.png │ │ ├── tab05_sel.png │ │ └── tab05_unsel.png │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── custom_in_xmlactivity.xml │ │ ├── fragment_common.xml │ │ ├── fragment_sample.xml │ │ ├── quick_start_activity.xml │ │ └── use_in_fragment.xml │ │ ├── mipmap-hdpi │ │ ├── app_logo.png │ │ └── ic_launcher.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 │ └── heima │ └── tabview │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── tabviewlibrary ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src ├── androidTest └── java │ └── com │ └── heima │ └── tabview │ └── library │ └── ApplicationTest.java ├── main ├── AndroidManifest.xml ├── java │ └── com │ │ └── heima │ │ └── tabview │ │ └── library │ │ ├── TabView.java │ │ ├── TabViewChild.java │ │ └── TabViewUtil.java └── res │ └── values │ ├── attrs.xml │ └── ids.xml └── test └── java └── com └── heima └── tabview └── library └── ExampleUnitTest.java /.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 | 23 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.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 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.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 | # FragmentTabhostUtils 2 | --- 3 | 开源地址:[https://github.com/open-android/FragmentTabhostUtils](https://github.com/open-android/FragmentTabhostUtils) 4 | 5 | 这是一个封装了android常用的底部导航栏+fragment的库,用这个库,我们可以几行代码就搞定大多数APP的主界面的布局 6 | 7 | ![image](https://github.com/yaochangliang159/Android-TabView/raw/master/screenshot/image_left.jpg) 8 | ![image](https://github.com/yaochangliang159/Android-TabView/raw/master/screenshot/image_top.jpg) 9 | ![image](https://github.com/yaochangliang159/Android-TabView/raw/master/screenshot/image_right.jpg) 10 | ![image](https://github.com/yaochangliang159/Android-TabView/raw/master/screenshot/image_bottom.jpg) 11 | 12 | * 爱生活,爱学习,更爱做代码的搬运工,分类查找更方便请下载黑马助手app 13 | 14 | 15 | ![黑马助手.png](http://upload-images.jianshu.io/upload_images/4037105-f777f1214328dcc4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 16 | 17 | ## 使用步骤 18 | 19 | 20 | ### 1. 在project的build.gradle添加如下代码(如下图) 21 | 22 | allprojects { 23 | repositories { 24 | maven { url "https://jitpack.io" } 25 | } 26 | } 27 | ![](http://upload-images.jianshu.io/upload_images/4037105-2faa5daca3bfe8a0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 28 | 29 | Sync项目以后,引入这个库就成功了~~~ 30 | ### 2. 在Module的build.gradle添加依赖 31 | 32 | 33 | compile 'com.github.open-android:FragmentTabhostUtils:0.5.0' 34 | 35 | ### 3. 在xml中,加入以下代码: 36 | 37 | 41 | 42 | 43 | 44 | ### 4. 在项目当中添加如下代码: 45 | 46 | List tabViewChildList=new ArrayList<>(); 47 | TabViewChild tabViewChild01=new TabViewChild(R.drawable.tab01_sel,R.drawable.tab01_unsel,"首页", FragmentCommon.newInstance()); 48 | TabViewChild tabViewChild02=new TabViewChild(R.drawable.tab02_sel,R.drawable.tab02_unsel,"分类", FragmentCommon.newInstance()); 49 | TabViewChild tabViewChild03=new TabViewChild(R.drawable.tab03_sel,R.drawable.tab03_unsel,"资讯", FragmentCommon.newInstance()); 50 | TabViewChild tabViewChild04=new TabViewChild(R.drawable.tab04_sel,R.drawable.tab04_unsel,"购物车",FragmentCommon.newInstance()); 51 | TabViewChild tabViewChild05=new TabViewChild(R.drawable.tab05_sel,R.drawable.tab05_unsel,"我的", FragmentCommon.newInstance()); 52 | tabViewChildList.add(tabViewChild01); 53 | tabViewChildList.add(tabViewChild02); 54 | tabViewChildList.add(tabViewChild03); 55 | tabViewChildList.add(tabViewChild04); 56 | tabViewChildList.add(tabViewChild05); 57 | 58 | > 是不是看起来感觉好复杂?其实就是new了5个实体类,把这5个实体类添加到了一个集合里,我们最终想要的是tabViewChildList这个集合,每个实体类的构造方法有四个参数: 59 | 60 | * 第一个参数:导航栏上面的某一个tab被点击时候,相应的切换的图片 61 | * 第二个参数:导航栏上面的tab没有被被点击时候,相应的切换的图片 62 | * 第三个参数:导航栏上面的某一个tab的文字显示 63 | * 第四个参数:导航栏上面的某一个tab对应的Fragment对象,传进来就可以 64 | 65 | 66 | ### 5 为TabView设置数据源: 67 | 68 | TabView tabView= (TabView) findViewById(R.id.tabView); 69 | tabView.setTabViewChild(tabViewChildList,getSupportFragmentManager()); 70 | tabView.setOnTabChildClickListener(new TabView.OnTabChildClickListener() { 71 | @Override 72 | public void onTabChildClick(int position, ImageView currentImageIcon, TextView currentTextView) { 73 | Toast.makeText(getApplicationContext(),"position:"+position,Toast.LENGTH_SHORT).show(); 74 | } 75 | }); 76 | 77 | --- 78 | 79 | 当然,还能自定义很多属性 80 | 81 | ### 在JAVA代码里自定义 82 | 83 | tabView.setTextViewSelectedColor(Color.BLUE); 84 | tabView.setTextViewUnSelectedColor(Color.BLACK); 85 | tabView.setTabViewBackgroundColor(Color.YELLOW); 86 | tabView.setTabViewHeight(dip2px(52)); 87 | tabView.setImageViewTextViewMargin(2); 88 | tabView.setTextViewSize(14); 89 | tabView.setImageViewWidth(dip2px(30)); 90 | tabView.setImageViewHeight(dip2px(30)); 91 | tabView.setTabViewGravity(Gravity.TOP); 92 | tabView.setTabViewDefaultPosition(2); 93 | 94 | ### 在xml中自定义: 95 | 96 | 111 | 112 | 113 | * 详细的使用方法在DEMO里面都演示啦,如果你觉得这个库还不错,请赏我一颗star吧~~~ 114 | 115 | * 欢迎关注微信公众号 116 | 117 | ![](http://oi5nqn6ce.bkt.clouddn.com/itheima/booster/code/qrcode.png) 118 | -------------------------------------------------------------------------------- /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 | 7 | defaultConfig { 8 | applicationId "com.ycl.tabview" 9 | minSdkVersion 14 10 | targetSdkVersion 24 11 | versionCode 1 12 | versionName "1.0" 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 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:24.1.1' 26 | compile project(':tabviewlibrary') 27 | 28 | } 29 | -------------------------------------------------------------------------------- /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 F:\android-sdk01/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/heima/tabview/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.heima.tabview; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/heima/tabview/CustomInJavaActivity.java: -------------------------------------------------------------------------------- 1 | package com.heima.tabview; 2 | 3 | import android.graphics.Color; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.FragmentActivity; 7 | import android.view.Gravity; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | import com.heima.tabview.library.TabView; 11 | import com.heima.tabview.library.TabViewChild; 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | 16 | public class CustomInJavaActivity extends FragmentActivity { 17 | TabView tabView; 18 | @Override protected void onCreate(@Nullable Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.quick_start_activity); 21 | 22 | tabView= (TabView) findViewById(R.id.tabView); 23 | //start add data 24 | List tabViewChildList=new ArrayList<>(); 25 | TabViewChild tabViewChild01=new TabViewChild(R.drawable.tab01_sel,R.drawable.tab01_unsel,"首页", FragmentCommon.newInstance("首页")); 26 | TabViewChild tabViewChild02=new TabViewChild(R.drawable.tab02_sel,R.drawable.tab02_unsel,"分类", FragmentCommon.newInstance("分类")); 27 | TabViewChild tabViewChild03=new TabViewChild(R.drawable.tab03_sel,R.drawable.tab03_unsel,"资讯", FragmentCommon.newInstance("资讯")); 28 | TabViewChild tabViewChild04=new TabViewChild(R.drawable.tab04_sel,R.drawable.tab04_unsel,"购物车",FragmentCommon.newInstance("购物车")); 29 | TabViewChild tabViewChild05=new TabViewChild(R.drawable.tab05_sel,R.drawable.tab05_unsel,"我的", FragmentCommon.newInstance("我的")); 30 | tabViewChildList.add(tabViewChild01); 31 | tabViewChildList.add(tabViewChild02); 32 | tabViewChildList.add(tabViewChild03); 33 | tabViewChildList.add(tabViewChild04); 34 | tabViewChildList.add(tabViewChild05); 35 | //end add data 36 | //start custom style 37 | tabView.setTextViewSelectedColor(Color.BLUE); 38 | tabView.setTextViewUnSelectedColor(Color.BLACK); 39 | tabView.setTabViewBackgroundColor(Color.YELLOW); 40 | tabView.setTabViewHeight(dip2px(52)); 41 | tabView.setImageViewTextViewMargin(2); 42 | tabView.setTextViewSize(14); 43 | tabView.setImageViewWidth(dip2px(30)); 44 | tabView.setImageViewHeight(dip2px(30)); 45 | tabView.setTabViewGravity(Gravity.TOP); 46 | tabView.setTabViewDefaultPosition(2); 47 | //end of custom 48 | tabView.setTabViewChild(tabViewChildList,getSupportFragmentManager()); 49 | tabView.setOnTabChildClickListener(new TabView.OnTabChildClickListener() { 50 | @Override 51 | public void onTabChildClick(int position, ImageView currentImageIcon, TextView currentTextView) { 52 | // Toast.makeText(getApplicationContext(),"position:"+position,Toast.LENGTH_SHORT).show(); 53 | } 54 | }); 55 | } 56 | 57 | public int dip2px(float dpValue) 58 | { 59 | final float scale = getResources().getDisplayMetrics().density; 60 | return (int) (dpValue * scale + 0.5f); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/com/heima/tabview/CustomInXmlActivity.java: -------------------------------------------------------------------------------- 1 | package com.heima.tabview; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.FragmentActivity; 5 | import android.widget.ImageView; 6 | import android.widget.TextView; 7 | import android.widget.Toast; 8 | 9 | import com.heima.tabview.library.TabView; 10 | import com.heima.tabview.library.TabViewChild; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | 15 | public class CustomInXmlActivity extends FragmentActivity { 16 | TabView tabView; 17 | 18 | @Override 19 | public void onCreate(Bundle savedInstanceState){ 20 | super.onCreate(savedInstanceState); 21 | setContentView(R.layout.custom_in_xmlactivity); 22 | 23 | TabView tabView= (TabView) findViewById(R.id.tabView); 24 | //start add data 25 | List tabViewChildList=new ArrayList<>(); 26 | TabViewChild tabViewChild01=new TabViewChild(R.drawable.tab01_sel,R.drawable.tab01_unsel,"首页", FragmentCommon.newInstance("首页")); 27 | TabViewChild tabViewChild02=new TabViewChild(R.drawable.tab02_sel,R.drawable.tab02_unsel,"分类", FragmentCommon.newInstance("分类")); 28 | TabViewChild tabViewChild03=new TabViewChild(R.drawable.tab03_sel,R.drawable.tab03_unsel,"资讯", FragmentCommon.newInstance("资讯")); 29 | TabViewChild tabViewChild04=new TabViewChild(R.drawable.tab04_sel,R.drawable.tab04_unsel,"购物车",FragmentCommon.newInstance("购物车")); 30 | TabViewChild tabViewChild05=new TabViewChild(R.drawable.tab05_sel,R.drawable.tab05_unsel,"我的", FragmentCommon.newInstance("我的")); 31 | tabViewChildList.add(tabViewChild01); 32 | tabViewChildList.add(tabViewChild02); 33 | tabViewChildList.add(tabViewChild03); 34 | tabViewChildList.add(tabViewChild04); 35 | tabViewChildList.add(tabViewChild05); 36 | //end add data 37 | tabView.setTabViewDefaultPosition(2); 38 | tabView.setTabViewChild(tabViewChildList,getSupportFragmentManager()); 39 | tabView.setOnTabChildClickListener(new TabView.OnTabChildClickListener() { 40 | @Override 41 | public void onTabChildClick(int position, ImageView currentImageIcon, TextView currentTextView) { 42 | Toast.makeText(getApplicationContext(),"position:"+position,Toast.LENGTH_SHORT).show(); 43 | } 44 | }); 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/heima/tabview/FragmentCommon.java: -------------------------------------------------------------------------------- 1 | package com.heima.tabview; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.TextView; 10 | 11 | 12 | public class FragmentCommon extends Fragment { 13 | TextView textView; 14 | 15 | public static FragmentCommon newInstance(String text){ 16 | FragmentCommon fragmentCommon=new FragmentCommon(); 17 | Bundle bundle=new Bundle(); 18 | bundle.putString("text",text); 19 | fragmentCommon.setArguments(bundle); 20 | return fragmentCommon; 21 | } 22 | @Nullable @Override 23 | public View onCreateView(LayoutInflater inflater, 24 | @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 25 | View view=inflater.inflate(R.layout.fragment_common,container,false); 26 | textView= (TextView) view.findViewById(R.id.textView); 27 | textView.setText(getArguments().getString("text")); 28 | return view; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/heima/tabview/FragmentSample.java: -------------------------------------------------------------------------------- 1 | package com.heima.tabview; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ImageView; 10 | import android.widget.TextView; 11 | import com.heima.tabview.library.TabView; 12 | import com.heima.tabview.library.TabViewChild; 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | 17 | public class FragmentSample extends Fragment { 18 | TabView tabView; 19 | @Nullable @Override 20 | public View onCreateView(LayoutInflater inflater, 21 | @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 22 | View view=inflater.inflate(R.layout.fragment_sample,container,false); 23 | tabView= (TabView) view.findViewById(R.id.tabView); 24 | init(); 25 | return view; 26 | } 27 | private void init(){ 28 | //start add data 29 | List tabViewChildList=new ArrayList<>(); 30 | TabViewChild tabViewChild01=new TabViewChild(R.drawable.tab01_sel,R.drawable.tab01_unsel,"首页", FragmentCommon.newInstance("首页")); 31 | TabViewChild tabViewChild02=new TabViewChild(R.drawable.tab02_sel,R.drawable.tab02_unsel,"分类", FragmentCommon.newInstance("分类")); 32 | TabViewChild tabViewChild03=new TabViewChild(R.drawable.tab03_sel,R.drawable.tab03_unsel,"资讯", FragmentCommon.newInstance("资讯")); 33 | TabViewChild tabViewChild04=new TabViewChild(R.drawable.tab04_sel,R.drawable.tab04_unsel,"购物车",FragmentCommon.newInstance("购物车")); 34 | TabViewChild tabViewChild05=new TabViewChild(R.drawable.tab05_sel,R.drawable.tab05_unsel,"我的", FragmentCommon.newInstance("我的")); 35 | tabViewChildList.add(tabViewChild01); 36 | tabViewChildList.add(tabViewChild02); 37 | tabViewChildList.add(tabViewChild03); 38 | tabViewChildList.add(tabViewChild04); 39 | tabViewChildList.add(tabViewChild05); 40 | //end add data 41 | tabView.setTabViewDefaultPosition(2); 42 | tabView.setTabViewChild(tabViewChildList,getChildFragmentManager()); 43 | tabView.setOnTabChildClickListener(new TabView.OnTabChildClickListener() { 44 | @Override 45 | public void onTabChildClick(int position, ImageView currentImageIcon, TextView currentTextView) { 46 | // Toast.makeText(getApplicationContext(),"position:"+position,Toast.LENGTH_SHORT).show(); 47 | } 48 | }); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/heima/tabview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.heima.tabview; 2 | 3 | import android.content.Intent; 4 | import android.support.v4.app.FragmentActivity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | 8 | public class MainActivity extends FragmentActivity { 9 | 10 | 11 | @Override 12 | protected void onCreate(Bundle savedInstanceState) { 13 | super.onCreate(savedInstanceState); 14 | setContentView(R.layout.activity_main); 15 | } 16 | public void quick_start(View view){ 17 | startActivity(new Intent(this,QuickStartActivity.class)); 18 | } 19 | public void custom_in_xml(View view){ 20 | startActivity(new Intent(this,CustomInXmlActivity.class)); 21 | } 22 | public void custom_in_java(View view){ 23 | startActivity(new Intent(this,CustomInJavaActivity.class)); 24 | } 25 | public void use_in_fragment(View view){ 26 | startActivity(new Intent(this,UseInFragment.class)); 27 | } 28 | 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/heima/tabview/QuickStartActivity.java: -------------------------------------------------------------------------------- 1 | package com.heima.tabview; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.FragmentActivity; 6 | import android.widget.ImageView; 7 | import android.widget.TextView; 8 | import com.heima.tabview.library.TabView; 9 | import com.heima.tabview.library.TabViewChild; 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | 14 | public class QuickStartActivity extends FragmentActivity { 15 | TabView tabView; 16 | 17 | 18 | @Override protected void onCreate(@Nullable Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.quick_start_activity); 21 | 22 | tabView= (TabView) findViewById(R.id.tabView); 23 | //start add data 24 | List tabViewChildList=new ArrayList<>(); 25 | TabViewChild tabViewChild01=new TabViewChild(R.drawable.tab01_sel,R.drawable.tab01_unsel,"首页", FragmentCommon.newInstance("首页")); 26 | TabViewChild tabViewChild02=new TabViewChild(R.drawable.tab02_sel,R.drawable.tab02_unsel,"分类", FragmentCommon.newInstance("分类")); 27 | TabViewChild tabViewChild03=new TabViewChild(R.drawable.tab03_sel,R.drawable.tab03_unsel,"资讯", FragmentCommon.newInstance("资讯")); 28 | TabViewChild tabViewChild04=new TabViewChild(R.drawable.tab04_sel,R.drawable.tab04_unsel,"购物车",FragmentCommon.newInstance("购物车")); 29 | TabViewChild tabViewChild05=new TabViewChild(R.drawable.tab05_sel,R.drawable.tab05_unsel,"我的", FragmentCommon.newInstance("我的")); 30 | tabViewChildList.add(tabViewChild01); 31 | tabViewChildList.add(tabViewChild02); 32 | tabViewChildList.add(tabViewChild03); 33 | tabViewChildList.add(tabViewChild04); 34 | tabViewChildList.add(tabViewChild05); 35 | //end add data 36 | tabView.setTabViewDefaultPosition(2); 37 | tabView.setTabViewChild(tabViewChildList,getSupportFragmentManager()); 38 | tabView.setOnTabChildClickListener(new TabView.OnTabChildClickListener() { 39 | @Override 40 | public void onTabChildClick(int position, ImageView currentImageIcon, TextView currentTextView) { 41 | // Toast.makeText(getApplicationContext(),"position:"+position,Toast.LENGTH_SHORT).show(); 42 | } 43 | }); 44 | } 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/heima/tabview/UseInFragment.java: -------------------------------------------------------------------------------- 1 | package com.heima.tabview; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.FragmentActivity; 5 | 6 | 7 | public class UseInFragment extends FragmentActivity { 8 | FragmentSample fragmentSample; 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.use_in_fragment); 14 | fragmentSample=new FragmentSample(); 15 | getSupportFragmentManager().beginTransaction().add(R.id.frame,fragmentSample).show(fragmentSample).commit(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/tab01_sel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-android/FragmentTabhostUtils/29edb708dd8d919af403f093a8277dff3cd9ee22/app/src/main/res/drawable-hdpi/tab01_sel.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/tab01_unsel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-android/FragmentTabhostUtils/29edb708dd8d919af403f093a8277dff3cd9ee22/app/src/main/res/drawable-hdpi/tab01_unsel.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/tab02_sel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-android/FragmentTabhostUtils/29edb708dd8d919af403f093a8277dff3cd9ee22/app/src/main/res/drawable-hdpi/tab02_sel.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/tab02_unsel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-android/FragmentTabhostUtils/29edb708dd8d919af403f093a8277dff3cd9ee22/app/src/main/res/drawable-hdpi/tab02_unsel.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/tab03_sel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-android/FragmentTabhostUtils/29edb708dd8d919af403f093a8277dff3cd9ee22/app/src/main/res/drawable-hdpi/tab03_sel.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/tab03_unsel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-android/FragmentTabhostUtils/29edb708dd8d919af403f093a8277dff3cd9ee22/app/src/main/res/drawable-hdpi/tab03_unsel.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/tab04_sel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-android/FragmentTabhostUtils/29edb708dd8d919af403f093a8277dff3cd9ee22/app/src/main/res/drawable-hdpi/tab04_sel.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/tab04_unsel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-android/FragmentTabhostUtils/29edb708dd8d919af403f093a8277dff3cd9ee22/app/src/main/res/drawable-hdpi/tab04_unsel.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/tab05_sel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-android/FragmentTabhostUtils/29edb708dd8d919af403f093a8277dff3cd9ee22/app/src/main/res/drawable-hdpi/tab05_sel.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/tab05_unsel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-android/FragmentTabhostUtils/29edb708dd8d919af403f093a8277dff3cd9ee22/app/src/main/res/drawable-hdpi/tab05_unsel.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 |