ad728

Monday, October 10, 2016

AIDE Tutorial 24 TabHost

Main xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="top">
    <TabHost android:id="@+id/th"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/one"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:text="android smartphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:id="@+id/two"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:text="apple smartphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:id="@+id/three"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
Java

package com.mycompany.tb;
import android.app.*;
import android.os.*;
import android.widget.*;

public class MainActivity extends Activity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
  
TabHost th=(TabHost)findViewById(R.id.th);
th.setup();



TabHost.TabSpec sp=th.newTabSpec("");
sp.setContent(R.id.one);
sp.setIndicator("Android");
th.addTab(sp);

sp=th.newTabSpec("");
sp.setContent(R.id.two);
sp.setIndicator("iphone");
th.addTab(sp);

sp=th.newTabSpec("");
sp.setContent(R.id.three);
sp.setIndicator("myphone");
th.addTab(sp);
   }
}


Share:

0 comments:

Post a Comment

Total Pageviews

Sponsor

Sponsor

ad300