[英]Is there any way to add tab layout without letting the activity to extend TabActivity?
I want to add tabs to the layout of my activity, but I don't want the activity to extend TabActivity. 我想在我的活动布局中添加选项卡,但我不希望活动扩展TabActivity。 The example in http://developer.android.com/resources/tutorials/views/hello-tabwidget.html only gave example of subclass of TabActivity.
http://developer.android.com/resources/tutorials/views/hello-tabwidget.html中的示例仅提供了TabActivity的子类示例。
Is there any way I can make it without extending TabActivity? 有没有办法在没有扩展TabActivity的情况下实现它?
Thanks. 谢谢。
I figured it out. 我想到了。
In Xml file I should define TabHost like below: 在Xml文件中,我应该像下面这样定义TabHost:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mytabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
In Java file: 在Java文件中:
public class HelloTest extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = (TabHost) findViewById(R.id.mytabhost);
tabHost.setup();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.