Android FragmentTabHost

//xml

Android FragmentTabHost_第1张图片
main activity

FragmentTabHost fragmentTabHost =null;

//图片资源

private int mImages[] = {  R.drawable.tab_counter, R.drawable.tab_contest};

fragmentTabHost=(FragmentTabHost)findViewById(android.R.id.tabhost);

fragmentTabHost.setup(this,getSupportFragmentManager(),android.R.id.tabcontent);

//添加页面fragmentTabHost.addTab(fragmentTabHost.newTabSpec("sdsss").setIndicator(getImageView(0)),Dsfs.class,null);

fragmentTabHost.addTab(fragmentTabHost.newTabSpec("sds").setIndicator(getImageView(1)),Fsdfs.class,null);

// 获得图片资源private View getImageView(int index) {    @SuppressLint("InflateParams")    View view = getLayoutInflater().inflate(R.layout.view_tab_indicator, null);    ImageView imageView = (ImageView) view.findViewById(R.id.tab_iv_image);    imageView.setImageResource(mImages[index]);    return view;}

你可能感兴趣的:(Android FragmentTabHost)