public class MainActivity extends FragmentActivity implements OnClickListener{
private ImageView sou;
private List<Fragment> list;
private ImageView shou;
private ImageView pin;
private ImageView gou;
private ImageView geng;
private TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
sou = (ImageView)findViewById(R.id.sou);
shou = (ImageView)findViewById(R.id.shou);
pin = (ImageView)findViewById(R.id.pin);
gou = (ImageView)findViewById(R.id.gou);
geng = (ImageView)findViewById(R.id.geng);
shou.setOnClickListener(this);
sou.setOnClickListener(this);
pin.setOnClickListener(this);
gou.setOnClickListener(this);
geng.setOnClickListener(this);
FragmentManager fragmentManager = getSupportFragmentManager();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment,new Shou()).commit();
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.shou:
System.out.println("=============");
shou.setBackground(getResources().getDrawable(R.drawable.bar_home_selected));
sou.setBackground(getResources().getDrawable(R.drawable.bar_search_normal));
pin.setBackground(getResources().getDrawable(R.drawable.bar_class_normal));
gou.setBackground(getResources().getDrawable(R.drawable.bar_shopping_normal));
geng.setBackground(getResources().getDrawable(R.drawable.bar_more_normal));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment,new Shou()).commit();
break;
case R.id.sou:
sou.setBackground(getResources().getDrawable(R.drawable.bar_search_selected));
shou.setBackground(getResources().getDrawable(R.drawable.bar_home_normal));
pin.setBackground(getResources().getDrawable(R.drawable.bar_class_normal));
gou.setBackground(getResources().getDrawable(R.drawable.bar_shopping_normal));
geng.setBackground(getResources().getDrawable(R.drawable.bar_more_normal));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment,new Sou()).commit();
break;
case R.id.pin:
pin.setBackground(getResources().getDrawable(R.drawable.bar_class_selected));
shou.setBackground(getResources().getDrawable(R.drawable.bar_home_normal));
sou.setBackground(getResources().getDrawable(R.drawable.bar_search_normal));
gou.setBackground(getResources().getDrawable(R.drawable.bar_shopping_normal));
geng.setBackground(getResources().getDrawable(R.drawable.bar_more_normal));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment,new Pin()).commit();
break;
case R.id.gou:
gou.setBackground(getResources().getDrawable(R.drawable.bar_shopping_selected));
shou.setBackground(getResources().getDrawable(R.drawable.bar_home_normal));
sou.setBackground(getResources().getDrawable(R.drawable.bar_search_normal));
pin.setBackground(getResources().getDrawable(R.drawable.bar_class_normal));
geng.setBackground(getResources().getDrawable(R.drawable.bar_more_normal));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment,new Gou()).commit();
break;
case R.id.geng:
geng.setBackground(getResources().getDrawable(R.drawable.bar_more_selected));
shou.setBackground(getResources().getDrawable(R.drawable.bar_home_normal));
sou.setBackground(getResources().getDrawable(R.drawable.bar_search_normal));
pin.setBackground(getResources().getDrawable(R.drawable.bar_class_normal));
gou.setBackground(getResources().getDrawable(R.drawable.bar_shopping_normal));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment,new Geng()).commit();
break;
default:
break;
}
}
}