Demo:
1)Tabs Activity:
package com.venky.tabsdemo2;
2)Tab1 Activity:
3)Tab2 Activity:
4)Tab3 Activity:
5)main.xml:
6)tab1.xml:
7)tab2.xml:
8)tab3.xml:
1)Tabs Activity:
package com.venky.tabsdemo2;
import
android.app.TabActivity;
import
android.content.Intent;
import
android.os.Bundle;
import
android.widget.TabHost;
import
android.widget.TabHost.TabSpec;
public class TabsDemo2 extends TabActivity {
/** Called when the activity is first
created. */
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabSpec spec1 = tabHost.newTabSpec("Tab1");
spec1.setIndicator("Tab1");
Intent intentTab1 = new Intent(this, Tab1Activity.class);
spec1.setContent(intentTab1);
TabSpec spec2 = tabHost.newTabSpec("Tab2");
spec2.setIndicator("Tab2");
Intent intentTab2 = new Intent(this, Tab2Activity.class);
spec2.setContent(intentTab2);
TabSpec spec3 = tabHost.newTabSpec("Tab3");
spec3.setIndicator("Tab3");
Intent intentTab3 = new Intent(this, Tab3Activity.class);
spec3.setContent(intentTab3);
tabHost.addTab(spec1);
tabHost.addTab(spec2);
tabHost.addTab(spec3);
}
}
package
com.venky.tabsdemo2;
import
android.app.Activity;
import
android.os.Bundle;
public class Tab1Activity extends Activity {
@Override
protected void onCreate(Bundle
savedInstanceState) {
// TODO
Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tab1);
}
}
package
com.venky.tabsdemo2;
import
android.app.Activity;
import
android.os.Bundle;
public class Tab2Activity extends Activity {
@Override
protected void onCreate(Bundle
savedInstanceState) {
// TODO
Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tab2);
}
}
package
com.venky.tabsdemo2;
import
android.app.Activity;
import
android.os.Bundle;
public class Tab3Activity extends Activity {
@Override
protected void onCreate(Bundle
savedInstanceState) {
// TODO
Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tab3);
}
}
<?xml version="1.0"
encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<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="fill_parent"
>
</FrameLayout>
</TabHost>
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingTop="60dp"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is Tab 1
" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/one"
/>
</LinearLayout>
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingTop="60dp"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is Tab 2
" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/two"
/>
</LinearLayout>
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingTop="60dp"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is Tab 1
" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/three"
/>
</LinearLayout>
9)Download this Project Click Here
No comments:
Post a Comment