Skip to content

Commit 828a150

Browse files
committed
第二次提交
1 parent bda66c8 commit 828a150

16 files changed

Lines changed: 793 additions & 0 deletions

File tree

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ dependencies {
2424
testCompile 'junit:junit:4.12'
2525
compile 'com.android.support:appcompat-v7:24.1.1'
2626
compile project(':tabviewlibrary')
27+
2728
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.heima.tabview;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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<TabViewChild> 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+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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<TabViewChild> 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+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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<TabViewChild> 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+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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<TabViewChild> 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+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

app/src/main/res/layout/quick_start_activity.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
android:layout_height="match_parent"
55
android:orientation="vertical">
66

7+
78
<com.heima.tabview.library.TabView
89
android:id="@+id/tabView"
910
android:layout_width="match_parent"

0 commit comments

Comments
 (0)