主要核心部分
示例
List<Fragment> list_fragment;
List<String> list_title;
RelativeLayout rlBottom;
@Bind(R.id.fangwu_back)
ImageView fangwuBack;
@Bind(R.id.fangwu_etSouSuo)
EditText fangwuEtSouSuo;
@Bind(R.id.ivSouSuo)
ImageView ivSouSuo;
@Bind(R.id.fangwu_tiaojianSouSuo)
TextView fangwuTiaojianSouSuo;
@Bind(R.id.fangwu_tab)
TabLayout fangwuTab;
@Bind(R.id.fangwu_zhuZhai)
RadioButton fangwuZhuZhai;
@Bind(R.id.fangwu_shangPu)
RadioButton fangwuShangPu;
@Bind(R.id.rgButtons)
RadioGroup rgButtons;
@Bind(R.id.fangwu_ll_tv1)
LinearLayout fangwuLlTv1;
@Bind(R.id.fangwu_ll_tv2)
LinearLayout fangwuLlTv2;
@Bind(R.id.fangwu_ll_tv3)
LinearLayout fangwuLlTv3;
@Bind(R.id.fangwu_ll_tv4)
LinearLayout fangwuLlTv4;
@Bind(R.id.fangwu_viewpager)
ViewPager fangwuViewpager;
@Bind(R.id.fangwu_tv1)
TextView fangwuTv1;
@Bind(R.id.fangwu_XiaoXi)
RelativeLayout fangwuXiaoXi;
@Bind(R.id.fangwu_tv)
TextView fangwuTv;
@Bind(R.id.fangwu_fabu)
RelativeLayout fangwuFabu;
@Bind(R.id.imageView)
ImageView imageView;
private TabLayout mTitle;
private ViewPager viewPager;
private OrderTabAdapter adapter;
private Fragment_fangwu_shou_zhuzhai nan;
private Fragment_fangwu_shou_shangpu nv;
private int xs = 2;
private int xs2 = 1;
private int type = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_act_fangwu_chuzu);
ButterKnife.bind(this);
init();
}
private void init() {
mTitle = (TabLayout)findViewById(R.id.fangwu_tab);
viewPager = (ViewPager) findViewById(R.id.fangwu_viewpager);
//出售住宅默认 2 1
nan = new Fragment_fangwu_shou_zhuzhai();
nan.setUser(xs);
nan.setType(type);
//出租住宅默认 1 1
nv = new Fragment_fangwu_shou_shangpu();
//将Title的名字添加到list_title中
nv.setXs2(xs2);
nv.setType2(type);
list_title = new ArrayList<>();
list_title.add("出售");
list_title.add("出租");
//将Fragment装入list_Fragmet中
list_fragment = new ArrayList<>();
list_fragment.add(nan);
list_fragment.add(nv);
//设置TabLayout的模式
mTitle.setTabMode(TabLayout.MODE_SCROLLABLE);
mTitle.setTabGravity(0);
//为TabLayout添加tab名称
//初始化adapter
adapter = new OrderTabAdapter(this.getSupportFragmentManager(),list_fragment,list_title);
//viewpager加载adapter
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
TLog.log("position",position + "");
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
//TabLayout加载viewpager
mTitle.setupWithViewPager(viewPager);
mTitle.getTabAt(0 ).setText(list_title.get(0)).setIcon(R.drawable.hunlian_selector);
mTitle.getTabAt(1).setText(list_title.get(1)).setIcon(R.drawable.hunlian_nv_selector);
TLog.log("qingheyikans",mTitle.getTabCount()+"");
TLog.log("qingheyikan",viewPager.getCurrentItem()+"");
}
boolean var ,var2;
@OnClick({R.id.fangwu_back, R.id.ivSouSuo, R.id.fangwu_tiaojianSouSuo, R.id.fangwu_zhuZhai, R.id.fangwu_shangPu, R.id.fangwu_ll_tv1, R.id.fangwu_ll_tv2, R.id.fangwu_ll_tv3, R.id.fangwu_ll_tv4, R.id.fangwu_XiaoXi, R.id.fangwu_fabu})
public void onClick(View view) {
switch (view.getId()) {
case R.id.fangwu_back:
finish();
break;
case R.id.ivSouSuo:
break;
case R.id.fangwu_tiaojianSouSuo:
break;
case R.id.fangwu_zhuZhai:
//住宅
Log.e("jingye", "click");
fangwuShangPu.setSelected(false);
fangwuZhuZhai.setSelected(false);
nan.setType(1);
nv.setType2(1);
break;
case R.id.fangwu_shangPu:
//商铺
fangwuShangPu.setSelected(true);
fangwuZhuZhai.setSelected(true);
Log.e("jingye", "click");
nan.setType(2);
nv.setType2(2);
break;
case R.id.fangwu_ll_tv1:
//地区
break;
case R.id.fangwu_ll_tv2:
//价格
break;
case R.id.fangwu_ll_tv3:
//户型
break;
case R.id.fangwu_ll_tv4:
//出售 求购
break;
case R.id.fangwu_XiaoXi:
break;
case R.id.fangwu_fabu:
break;
}
}
}
如何实先tablayout文字渐变色。
记住 要在setupWithViewPager方法后调用。要在setupWithViewPager方法后调用。要在setupWithViewPager方法后调用。重要事情说三遍.....
调用setCustomView()方法
布局文件
![Uploading image_642376.png . . .]