我想创建一个由两个选项卡组成的应用程序,每个选项卡都运行自己的 web 视图。我可以创建标签,但不能管理他们的 webviews。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, fbActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("fb").setIndicator("fb",
res.getDrawable(R.drawable.ic_tab_fb))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, google.class);
spec = tabHost.newTabSpec("google").setIndicator("google",
res.getDrawable(R.drawable.ic_tab_google))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}