getTabHost() - 无法解析方法
问题描述:
我尝试使用this tutorial创建标签栏。但是,在这条线:getTabHost() - 无法解析方法
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);
}
我该如何解决它?
答
TabHost已过时,建议使用在本教程中的新材料设计标签布局: http://www.androidhive.info/2015/09/android-material-design-working-with-tabs/
请编辑和显示整个类。 –