I tried create a tab bar using this tutorial . But in this line:
TabHost tabHost = getTabHost();
I received the message:
Cannot resolve the method "getTabHost()"
This is my code:
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);
}
How can I fix it?
不建议使用TabHost,建议使用本教程中所示的新“材质设计”选项卡布局: http : //www.androidhive.info/2015/09/android-material-design-working-with-tabs/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.