开发者

Is there any way to add tab layout without letting the activity to extend TabActivity?

开发者 https://www.devze.com 2023-01-08 12:55 出处:网络
I want to add tabs to the l开发者_运维百科ayout of my activity, but I don\'t want the activity to extend TabActivity. The example in http://developer.android.com/resources/tutorials/views/hello-tabwid

I want to add tabs to the l开发者_运维百科ayout of my activity, but I don't want the activity to extend TabActivity. The example in http://developer.android.com/resources/tutorials/views/hello-tabwidget.html only gave example of subclass of TabActivity.

Is there any way I can make it without extending TabActivity?

Thanks.


I figured it out.

In Xml file I should define TabHost like below:

<?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:

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号