Judul : Tutorial Tablayout Android
link : Tutorial Tablayout Android
Tutorial Tablayout Android
Tutorial Tablayout Android
Berikut cara membuat Tablayout android dengan Eclipse.
Contoh Android Tablayout dengan 4 Activity
1. Tab Activity
Buat 4 class activity.
Download SOURCE CODE
Contoh Android Tablayout dengan 4 Activity
1. Tab Activity
Buat 4 class activity.
FacebookActivity.java
package com.akatog.android;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class FacebookActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("Facebook Tab Activity");
setContentView(textview);
}
}
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class FacebookActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("Facebook Tab Activity");
setContentView(textview);
}
}
TwitterActivity.java
package com.akatog.android;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class TwitterActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("Twitter Tab Activity");
setContentView(textview);
}
}
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class TwitterActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("Twitter Tab Activity");
setContentView(textview);
}
}
PathActivity.java
package com.akatog.android;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class PathActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("Path Tab Activity");
setContentView(textview);
}
}
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class PathActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("Path Tab Activity");
setContentView(textview);
}
}
YoutubeActivity.java
package com.akatog.android;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class YoutubeActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("Youtube Tab Activity");
setContentView(textview);
}
}
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class YoutubeActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("Youtube Tab Activity");
setContentView(textview);
}
}
MainActivity.java
package com.akatog.android;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MainActivity extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources ressources = getResources();
TabHost tabHost = getTabHost();
// Facebook tab
Intent intentFacebook = new Intent().setClass(this, FacebookActivity.class);
TabSpec tabSpecFacebook = tabHost
.newTabSpec("Facebook")
.setIndicator("", ressources.getDrawable(R.drawable.icon_facebook))
.setContent(intentFacebook);
// Twitter tab
Intent intentTwitter = new Intent().setClass(this, TwitterActivity.class);
TabSpec tabSpecTwitter = tabHost
.newTabSpec("Twitter")
.setIndicator("", ressources.getDrawable(R.drawable.icon_twitter))
.setContent(intentTwitter);
// Path tab
Intent intentPath = new Intent().setClass(this, PathActivity.class);
TabSpec tabSpecPath = tabHost
.newTabSpec("Path")
.setIndicator("", ressources.getDrawable(R.drawable.icon_path))
.setContent(intentPath);
// Youtube tab
Intent intentYoutube = new Intent().setClass(this, YoutubeActivity.class);
TabSpec tabSpecYoutube = tabHost
.newTabSpec("Youtube")
.setIndicator("", ressources.getDrawable(R.drawable.icon_youtube))
.setContent(intentYoutube);
// semua tabs
tabHost.addTab(tabSpecFacebook);
tabHost.addTab(tabSpecTwitter);
tabHost.addTab(tabSpecPath);
tabHost.addTab(tabSpecYoutube);
//set Windows tab as default (zero based)
tabHost.setCurrentTab(2);
}
}
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MainActivity extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources ressources = getResources();
TabHost tabHost = getTabHost();
// Facebook tab
Intent intentFacebook = new Intent().setClass(this, FacebookActivity.class);
TabSpec tabSpecFacebook = tabHost
.newTabSpec("Facebook")
.setIndicator("", ressources.getDrawable(R.drawable.icon_facebook))
.setContent(intentFacebook);
// Twitter tab
Intent intentTwitter = new Intent().setClass(this, TwitterActivity.class);
TabSpec tabSpecTwitter = tabHost
.newTabSpec("Twitter")
.setIndicator("", ressources.getDrawable(R.drawable.icon_twitter))
.setContent(intentTwitter);
// Path tab
Intent intentPath = new Intent().setClass(this, PathActivity.class);
TabSpec tabSpecPath = tabHost
.newTabSpec("Path")
.setIndicator("", ressources.getDrawable(R.drawable.icon_path))
.setContent(intentPath);
// Youtube tab
Intent intentYoutube = new Intent().setClass(this, YoutubeActivity.class);
TabSpec tabSpecYoutube = tabHost
.newTabSpec("Youtube")
.setIndicator("", ressources.getDrawable(R.drawable.icon_youtube))
.setContent(intentYoutube);
// semua tabs
tabHost.addTab(tabSpecFacebook);
tabHost.addTab(tabSpecTwitter);
tabHost.addTab(tabSpecPath);
tabHost.addTab(tabSpecYoutube);
//set Windows tab as default (zero based)
tabHost.setCurrentTab(2);
}
}
2. Layout
main.xml
<?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">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<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"
android:padding="5dp" />
</LinearLayout>
</TabHost>
<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">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<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"
android:padding="5dp" />
</LinearLayout>
</TabHost>
- Untuk hasilnya bisa lihat Video di atas
- Download Sourcenya dan Import di Eclips
SELAMAT BELAJAR DAN MENCOBA
Demikianlah Artikel Tutorial Tablayout Android
Sekianlah artikel Tutorial Tablayout Android kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.
Anda sekarang membaca artikel Tutorial Tablayout Android dengan alamat link http://akatog.blogspot.com/2015/02/tutorial-tablayout-android.html
0 comments:
Post a Comment