package com.like.duoroulianmeng;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;
public class Buttom_meun extends FragmentActivity {
TextView[] textView;// 定义一个数组装底部菜单的 TextView的ID
ImageView[] imageView;
int index;// 点击后视图下标
int currentTabIndex;// 当前视图下标
private FragmentManager fragmentManager;
Fragment[] mFragments;
private FragmentTransaction fragmentTransaction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_buttom_meun);
mFragments = new Fragment[5];
fragmentManager = this.getSupportFragmentManager();
mFragments[0] = fragmentManager.findFragmentById(R.id.shouye_fragment);
mFragments[1] = fragmentManager.findFragmentById(R.id.xianshitemai_fragment);
mFragments[2] = fragmentManager.findFragmentById(R.id.shequ_fragment);
mFragments[3] = fragmentManager.findFragmentById(R.id.gouwuche_fragment);
mFragments[4] = fragmentManager.findFragmentById(R.id.wode_fragment);
fragmentTransaction = fragmentManager.beginTransaction()
.hide(mFragments[0]).hide(mFragments[1]).hide(mFragments[2])
.hide(mFragments[3]).hide(mFragments[4]);
fragmentTransaction.show(mFragments[0]).commit();
textView = new TextView[5];
textView[0] = (TextView) findViewById(R.id.tv_shouye);
textView[1] = (TextView) findViewById(R.id.tv_xianshitemai);
textView[2] = (TextView) findViewById(R.id.tv_shequ);
textView[3] = (TextView) findViewById(R.id.tv_gouwuche);
textView[4] = (TextView) findViewById(R.id.tv_wode);
textView[0].setTextColor(0xFFFF5001);
imageView = new ImageView[5];
imageView[0] = (ImageView) findViewById(R.id.imageview4);
imageView[1] = (ImageView) findViewById(R.id.imageview5);
imageView[2] = (ImageView) findViewById(R.id.imageview6);
imageView[3] = (ImageView) findViewById(R.id.imageview7);
imageView[4] = (ImageView) findViewById(R.id.imageview8);
System.out.println(imageView[1]+"11111");
imageView[0].setSelected(true);
}
public void onTabClicked(View view) {
fragmentTransaction = fragmentManager.beginTransaction()
.hide(mFragments[0]).hide(mFragments[1]).hide(mFragments[2])
.hide(mFragments[3]).hide(mFragments[4]);
switch (view.getId()) {
case R.id.shouye:
index = 0;
break;
case R.id.xianshitemai:
index = 1;
break;
case R.id.shequ:
index = 2;
break;
case R.id.gouwuche:
index = 3;
break;
case R.id.wode:
index = 4;
break;
}
textView[currentTabIndex].setTextColor(0xFF9A9A9A);
imageView[currentTabIndex].setSelected(false);
textView[index].setTextColor(0xFFFF5001);
imageView[index].setSelected(true);
System.out.println(imageView[index]+"222222");
fragmentTransaction.show(mFragments[index]).commit();
currentTabIndex = index;
}
}