为什么运行出来的Tab没有了字体了?
我只是将Color.GREEN用16进制表示了出来,再运行的话,三个Fragment中Tab的字都消失了,这是什么情况?
我只是将Color.GREEN用16进制表示了出来,再运行的话,三个Fragment中Tab的字都消失了,这是什么情况?
2016-03-25
public class MainActivity extends FragmentActivity implements View.OnClickListener{
//声明ViewPager
private ViewPager mViewPager;//用来放置界面切换
private FragmentPagerAdapter mAdapter;
private List<Fragment> mViews;
//声明三个tab_Fragment
private LinearLayout mTabMemory;
private LinearLayout mTabWave;
private LinearLayout mTabSet;
//声明三个Fragment中的三个按钮
private ImageView mMemoryImg;
private ImageView mWaveImg;
private ImageView mSetImg;
//声明指示条中的字体
private TextView mMemoryTextView;
private TextView mWaveTextView;
private TextView mSetTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(6);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
//初始化ViewPager
mViewPager = (ViewPager) findViewById(R.id.id_viewPager);
mViews = new ArrayList<Fragment>();
//初始化三个TextView
mMemoryTextView = (TextView) findViewById(R.id.id_text_memory);
mWaveTextView = (TextView) findViewById(R.id.id_text_wave);
mSetTextView = (TextView) findViewById(R.id.id_text_set);
//初始化三个LinearLayout
mTabMemory = (LinearLayout) findViewById(R.id.id_tab_memory);
mTabWave = (LinearLayout) findViewById(R.id.id_tab_wave);
mTabSet = (LinearLayout) findViewById(R.id.id_tab_set);
//初始化三个Image
mMemoryImg = (ImageView) findViewById(R.id.id_tab_memory_image);
mWaveImg = (ImageView) findViewById(R.id.id_tab_wave_image);
mSetImg = (ImageView) findViewById(R.id.id_tab_set_image);
mTabMemory.setOnClickListener(this);
mTabWave.setOnClickListener(this);
mTabSet.setOnClickListener(this);
//数据集中的数据就是各个Fragment
MemoryFragment memoryFragment = new MemoryFragment();
WaveFragment waveFragment = new WaveFragment();
SetFragment setFragment = new SetFragment();
//依次将各个Fragment加入到mViews中
mViews.add(memoryFragment);
mViews.add(waveFragment);
mViews.add(setFragment);
//适配器的初始化
mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
return mViews.get(position);//返回一个个Fragment
}
@Override
public int getCount() {
return mViews.size();
}
};
//给ViewPager设置适配器
mViewPager.setAdapter(mAdapter);
mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int i, float v, int i1) {
}
@Override
public void onPageSelected(int p) {
resetTextView();
switch (p) {
case 0:
resetImg();
mMemoryImg.setImageResource(R.drawable.memory);
mMemoryTextView.setTextColor(0xfc5a0a);
break;
case 1:
resetImg();
mWaveImg.setImageResource(R.drawable.wave);
mWaveTextView.setTextColor(0xfc5a0a);
break;
case 2:
resetImg();
mSetImg.setImageResource(R.drawable.set);
mSetTextView.setTextColor(0xfc5a0a);
break;
}
}
@Override
public void onPageScrollStateChanged(int i) {
}
});
}
/**
* 改变按下按钮之后的图片
*/
private void resetImg() {
mMemoryImg.setImageResource(R.drawable.memory_nonchosen);
mWaveImg.setImageResource(R.drawable.wave_nonchosen);
mSetImg.setImageResource(R.drawable.set_nonchosen);
}
protected void resetTextView() {
mMemoryTextView.setTextColor(0x000000);
mWaveTextView.setTextColor(0x000000);
mSetTextView.setTextColor(0x000000);
}
public void onClick(View view){
switch (view.getId()){
case R.id.id_tab_memory:
mViewPager.setCurrentItem(0);
resetImg();
mMemoryImg.setImageResource(R.drawable.memory);
mMemoryTextView.setTextColor(0xfc5a0a);
break;
case R.id.id_tab_wave:
mViewPager.setCurrentItem(1);
resetImg();
mWaveImg.setImageResource(R.drawable.wave);
mSetTextView.setTextColor(0xfc5a0a);
break;
case R.id.id_tab_set:
mViewPager.setCurrentItem(2);
resetImg();
mSetImg.setImageResource(R.drawable.set);
mSetTextView.setTextColor(0xfc5a0a);
break;
default:
break;
}
}
}
举报