Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

I want to add tabs to the layout 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.

like image 239
user256239 Avatar asked Nov 28 '25 19:11

user256239


1 Answers

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();
like image 176
user256239 Avatar answered Nov 30 '25 09:11

user256239



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!