Android TabHost不显示意图

时间:2014-02-27 08:36:09

标签: android android-tabhost tabwidget

我正在使用单个标签应用TabHost。我正在使用setContent()的新意图。但是我在HostTab的FramLayout上出现了空白屏幕。我可以看到Tab但不是创建的Intent Layout.Any可以帮助我。

public class MainActivity extends FragmentActivity implements
 OnTabChangeListener{
private ViewPager mViewPager;
private TabHost mTabHost;

@Override
public void onResume()
{
    if(mLocalActivityManager!=null)
    mLocalActivityManager.dispatchResume();
    super.onResume();
}

@Override
public void onPause()
{

    mLocalActivityManager.dispatchPause(isFinishing());
    super.onPause();
}
LocalActivityManager mLocalActivityManager=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Tab Initialization
    mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mLocalActivityManager = new LocalActivityManager(this, false);
    mLocalActivityManager.dispatchCreate(savedInstanceState);
    mTabHost.setup(mLocalActivityManager);
    initialiseTabHost();

}
private static void AddTab(MainActivity activity, TabHost tabHost,
        TabHost.TabSpec tabSpec) {

    tabHost.addTab(tabSpec);

}


public void onTabChanged(String tag) {
    int pos = this.mTabHost.getCurrentTab();

}



// Tabs Creation
private void initialiseTabHost() {

 TextView  tv=new TextView(this);
 tv.setTextSize(25);
 tv.setGravity(Gravity.CENTER_VERTICAL);
 tv.setText("This Is Tab1 Activity");

 TextView  tv1=new TextView(this);
 tv1.setTextSize(25);
 tv1.setGravity(Gravity.CENTER_VERTICAL);
 tv1.setText("This Is Tab2 Activity");

 ImageView img=new ImageView(this);


 img.setBackgroundResource(R.drawable.facebook_main);

 MainActivity.AddTab(this,    this.mTabHost,this.mTabHost.newTabSpec("Tab1").setIndicator(img).setContent(new     Intent(MainActivity.this,copy1.class)));

mTabHost.setOnTabChangedListener(this);
}
}

0 个答案:

没有答案