|
| 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 | +} |
0 commit comments