我尝试使用this tutorial创建标签栏。但在这一行:
TabHost tabHost = getTabHost();
我收到了消息:
无法解析方法“getTabHost()”
这是我的代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_feeds);
//add tab bar
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, FeedsFriendsActivity.class);
spec = tabHost.newTabSpec("First").setIndicator("First")
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, FeedsBeersActivity.class);
spec = tabHost.newTabSpec("Second").setIndicator("Second")
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, FeedsNotificationActivity.class);
spec = tabHost.newTabSpec("Third").setIndicator("Third")
.setContent(intent);
tabHost.addTab(spec);
}
我该如何解决?
答案 0 :(得分:0)
不推荐使用TabHost,建议使用新的Material design选项卡布局,如本教程所示: http://www.androidhive.info/2015/09/android-material-design-working-with-tabs/