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

I want to add tabs to the layout of my activity, but I do not want the activity to extend TabActivity. An example at http://developer.android.com/resources/tutorials/views/hello-tabwidget.html gave only an example of a subclass of TabActivity.

Is there a way to do this without the TabActivity extension?

Thank.

+3
source share
1 answer

I get it.

In the Xml file, I have to specify TabHost, as shown 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 the 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();
+5
source

Source: https://habr.com/ru/post/1755851/


All Articles