I find older github use tabhost. github address
But tabhost is deprecated.
Is now can raised center tab with TabLayout?
You can try this code,its working for me:
My XML file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TabHost
android:id="#+id/tabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"></TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffc916"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Android" />
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#da8200"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Iphone tab" />
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#5b89ff"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Windows tab" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
Its my Activity file:
package com.example.sudiproy.tabproject;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TabHost;
public class MainActivity extends AppCompatActivity {
TabHost tabHost;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost host = (TabHost) findViewById(R.id.tabHost);
host.setup();
//Tab 1
TabHost.TabSpec spec = host.newTabSpec("Tab One");
spec.setContent(R.id.tab1);
spec.setIndicator("Android");
host.addTab(spec);
//Tab 2
spec = host.newTabSpec("Tab Two");
spec.setContent(R.id.tab2);
spec.setIndicator("Iphone");
host.addTab(spec);
//Tab 3
spec = host.newTabSpec("Tab Three");
spec.setContent(R.id.tab3);
spec.setIndicator("Window");
host.addTab(spec);
}
}
Related
I want to change text in my tab Bar to get text in singleLine and remove the bold style but how to do it ? Please show me the good way
My below code don't change anything...
Here my XMl code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabHost
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tabHost"
android:layout_gravity="right">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"></TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:id="#+id/text1"
android:text="#string/text_v1"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:id="#+id/text2"
android:text="#string/text_v2"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:id="#+id/text3"
android:text="#string/text_v3"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:id="#+id/text4"
android:text="#string/text_v4"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:id="#+id/text5"
android:text="#string/text_v5"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
Here the java code:
package com.atonfoaziz.tabs5;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TabHost tabHost;
TabHost.TabSpec spec;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabHost = (TabHost)findViewById(R.id.tabHost);
if (tabHost != null){
tabHost.setup();
spec = tabHost.newTabSpec("Tab I").setContent(R.id.linearLayout1).setIndicator("Contacts");
tabHost.addTab(spec);
spec = tabHost.newTabSpec("Tab II").setContent(R.id.linearLayout2).setIndicator("Calls");
tabHost.addTab(spec);
spec = tabHost.newTabSpec("Tab III").setContent(R.id.linearLayout3).setIndicator("Discussions");
tabHost.addTab(spec);
spec = tabHost.newTabSpec("Tab IV").setContent(R.id.linearLayout4).setIndicator("Research");
tabHost.addTab(spec);
spec = tabHost.newTabSpec("Tab V").setContent(R.id.linearLayout5).setIndicator("Settings");
tabHost.addTab(spec);
TabWidget widget = tabHost.getTabWidget();
int tabCount = widget.getTabCount();
for (int i = 0; i < tabCount; i++){
View view = widget.getChildTabViewAt(i);
if (view != null){
TextView textView = (TextView)findViewById(R.id.title);
if (textView != null){
textView.setAllCaps(false);
textView.setSingleLine(true);
textView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
if (Build.VERSION.SDK_INT < 23){
textView.setTextAppearance(this, R.style.tab_appereance);
} else {
textView.setTextAppearance(R.style.tab_appereance);
}
textView.setTextSize(16);
}
}
}
}
}
}
After adding tabhost and tabcontent can't create tabview.
How to add tab in android. I use below code to display tabs.
XML File:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/homeLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/dynamicLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dynamic" />
</LinearLayout>
<LinearLayout
android:id="#+id/staticLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Static" />
</LinearLayout>
</FrameLayout>
</TabWidget>
</LinearLayout>
</TabHost>
</LinearLayout>
Java File
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_view);
tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
tabSpec = tabHost.newTabSpec("dynamicTab");
tabSpec.setIndicator("Create Image");
tabSpec.setContent(R.id.dynamicLinearLayout);
tabHost.addTab(tabSpec);
tabSpec = tabHost.newTabSpec("staticTab");
tabSpec.setIndicator("Select Image");
tabSpec.setContent(R.id.staticLinearLayout);
tabHost.addTab(tabSpec);
tabHost.setCurrentTab(0);
}
Output is:
Can't load two tabs.
Please show where I make a mistake.?
tabSpec = tabHost.newTabSpec("dynamicTab");
tabSpec.setIndicator("Create Image");
tabSpec.setContent(R.id.dynamicLinearLayout);
tabHost.addTab(tabSpec);
tabSpec2 = tabHost.newTabSpec("staticTab");
tabSpec2.setIndicator("Select Image");
tabSpec2.setContent(R.id.staticLinearLayout);
tabHost2.addTab(tabSpec2);
tabHost.setCurrentTab(0);
for java part the answer of sakir is correct you can use it or use mine:
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
TabHost.TabSpec tabSpec = tabHost.newTabSpec("dynamicTab");
tabSpec.setIndicator("Create Image");
tabSpec.setContent(R.id.dynamicLinearLayout);
tabHost.addTab(tabSpec);
TabHost.TabSpec tabSpec1 = tabHost.newTabSpec("staticTab");
tabSpec1.setIndicator("Select Image");
tabSpec1.setContent(R.id.staticLinearLayout);
tabHost.addTab(tabSpec1);
tabHost.setCurrentTab(0);
for your xml part you must remove </TabWidget> and change:
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
to
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
i want to show Calendar View in tab3 but i have no idea
mainActivity.class
public MainActivity extends ActionBarActivity {
TabHost mTabHost;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CalendarView calendarView = new CalendarView(this);
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
mTabHost.setup();
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB1")
.setContent(R.id.tab1));
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB2")
.setContent(R.id.tab2));
mTabHost.addTab(mTabHost.newTabSpec("Calendar").setIndicator("TAB3")
.setContent(R.id.tab3));
mTabHost.setCurrentTab(0);
}
}
main_activity.xml it contain tabHost widget
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
ref tab 1-3
<include layout="#layout/activity_tab1" />
<include layout="#layout/activity_tab2" />
<include layout="#layout/activity_tab3" />
</FrameLayout>
</LinearLayout>
</TabHost>'
tab3.xml this tap i want to show calendar in it.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tab3"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CalendarView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/cldView" />
</LinearLayout>
</RelativeLayout>
Give the suggestion to me plsssss.
I am newbie in android. I developed an android application that shows 15 tabs. One problem is i can't see each tab's title fully. Is it tabs in the android is scrollable.
I use below code to create tabs. looking for better solution
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TabHost android:id="#android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent" android:id="#+id/linearLayout1" android:layout_height="match_parent" android:orientation="vertical">
<TabWidget android:layout_width="match_parent" android:layout_height="wrap_content" android:id="#android:id/tabs"></TabWidget>
<FrameLayout android:layout_width="match_parent" android:layout_height="500px" android:id="#android:id/tabcontent">
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab1">
<TextView android:text="Tab1 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab2">
<TextView android:text="Tab2 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab3">
<TextView android:text="Tab3 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab4">
<TextView android:text="Tab4 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab5">
<TextView android:text="Tab5 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab6">
<TextView android:text="Tab6 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab7">
<TextView android:text="Tab7 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab8">
<TextView android:text="Tab8 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab9">
<TextView android:text="Tab9 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab10">
<TextView android:text="Tab10 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab11">
<TextView android:text="Tab11 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab12">
<TextView android:text="Tab12 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab13">
<TextView android:text="Tab13 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab14">
<TextView android:text="Tab14 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab15">
<TextView android:text="Tab15 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
activity class
package mtx.samples;
import android.app.AlertDialog;
import android.app.TabActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class NewTabAppActivity extends TabActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final AlertDialog.Builder ad = new AlertDialog.Builder(this);
TabHost tabHost = getTabHost();
// tab1
TabSpec ts1 = tabHost.newTabSpec("Tab1");
ts1.setIndicator("Tab 1", getResources().getDrawable(R.drawable.rss));
ts1.setContent(R.id.tab1);
tabHost.addTab(ts1);
// tab2
TabSpec ts2 = tabHost.newTabSpec("Tab2");
ts2.setIndicator("Tab 2");
ts2.setContent(R.id.tab2);
tabHost.addTab(ts2);
// tab3
TabSpec ts3 = tabHost.newTabSpec("Tab3");
ts3.setIndicator("Tab 3");
ts3.setContent(R.id.tab3);
tabHost.addTab(ts3);
// tab4
TabSpec ts4 = tabHost.newTabSpec("Tab4");
ts4.setIndicator("Tab 4");
ts4.setContent(R.id.tab4);
tabHost.addTab(ts4);
// tab5
TabSpec ts5 = tabHost.newTabSpec("Tab5");
ts5.setIndicator("Tab 5");
ts5.setContent(R.id.tab5);
tabHost.addTab(ts5);
// tab6
TabSpec ts6 = tabHost.newTabSpec("Tab6");
ts6.setIndicator("Tab 6");
ts6.setContent(R.id.tab6);
tabHost.addTab(ts6);
// tab7
TabSpec ts7 = tabHost.newTabSpec("Tab7");
ts7.setIndicator("Tab 7");
ts7.setContent(R.id.tab7);
tabHost.addTab(ts7);
// tab8
TabSpec ts8 = tabHost.newTabSpec("Tab8");
ts8.setIndicator("Tab 8");
ts8.setContent(R.id.tab8);
tabHost.addTab(ts8);
// tab9
TabSpec ts9 = tabHost.newTabSpec("Tab9");
ts9.setIndicator("Tab 9");
ts9.setContent(R.id.tab9);
tabHost.addTab(ts9);
// tab10
TabSpec ts10 = tabHost.newTabSpec("Tab10");
ts10.setIndicator("Tab 10");
ts10.setContent(R.id.tab10);
tabHost.addTab(ts10);
// tab11
TabSpec ts11 = tabHost.newTabSpec("Tab11");
ts11.setIndicator("Tab 11");
ts11.setContent(R.id.tab11);
tabHost.addTab(ts11);
// tab12
TabSpec ts12 = tabHost.newTabSpec("Tab12");
ts12.setIndicator("Tab 12");
ts12.setContent(R.id.tab12);
tabHost.addTab(ts12);
// tab13
TabSpec ts13 = tabHost.newTabSpec("Tab13");
ts13.setIndicator("Tab 13");
ts13.setContent(R.id.tab13);
tabHost.addTab(ts13);
// tab14
TabSpec ts14 = tabHost.newTabSpec("Tab14");
ts14.setIndicator("Tab 14");
ts14.setContent(R.id.tab14);
tabHost.addTab(ts14);
// tab15
TabSpec ts15 = tabHost.newTabSpec("Tab15");
ts15.setIndicator("Tab 15");
ts15.setContent(R.id.tab15);
tabHost.addTab(ts15);
ad.setTitle("NewTabApp");
ad.setNeutralButton("OK", null );
Button btnSendSettings = (Button)findViewById(R.id.btnSendSettings);
btnSendSettings.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
ad.setMessage("Send Settings button Clicked");
ad.show();
}
});
Button btnClose = (Button)findViewById(R.id.btnClose);
btnClose.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
System.exit(-1);
}
});
Button btnSave = (Button)findViewById(R.id.btnSave);
btnSave.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ad.setMessage("Save button Clicked");
ad.show();
}
});
Button btnSend = (Button)findViewById(R.id.btnSend);
btnSend.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
ad.setMessage("Send button Clicked");
ad.show();
}
});
}
}
you can make scrolling tabs in android using HorizontalScrollView in your layout xml file .
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none">
<TabWidget android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</HorizontalScrollView>
For reference go through the link :
scrolling-tabs-android
Hope this will help you to solve your issue.
I need sample code to create TabHost in android.
can anyone help me.
The Android Developer site has an excellent fully worked code sample for creating tabs in Android using the TabWidget and TabHost.
Check out Hello, TabWidget.
I had done tabhost related code with respect to displaying scores
TabHost host = getTabHost();
host.setup ();
TabSpec allScoresTab = host.newTabSpec("allTab");
allScoresTab.setIndicator(getResources().getString(R.string.all_scores), getResources().getDrawable(android.R.drawable.star_on));
allScoresTab.setContent(R.id.ScrollViewAllScores);
host.addTab(allScoresTab);
TabSpec friendScoresTab = host.newTabSpec("friendsTab");
friendScoresTab.setIndicator(getResources().getString(R.string.friends_scores), getResources().getDrawable(android.R.drawable.star_on));
friendScoresTab.setContent(R.id.ScrollViewFriendScores);
host.addTab(friendScoresTab);
host.setCurrentTabByTag("allTab");
My xml contains :
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bkgrnd">
<RelativeLayout
android:id="#+id/RelativeLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ImageView_Header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/quizicon"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true">
</ImageView>
<TextView
android:id="#+id/TextView01"
android:layout_height="wrap_content"
android:text="#string/scores"
android:textSize="#dimen/screen_title_size"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="10"
android:layout_width="wrap_content"
android:layout_gravity="fill_horizontal|center"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:shadowColor="#android:color/white"
android:textColor="#color/title_color">
</TextView>
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ImageView_Header2"
android:layout_height="wrap_content"
android:src="#drawable/quizicon"
android:layout_gravity="right|center_vertical"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true">
</ImageView>
</RelativeLayout>
<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">
<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">
<ScrollView android:id="#+id/ScrollViewAllScores" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbars="vertical">
<TableLayout android:id="#+id/TableLayout_AllScores" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="*" />
</ScrollView>
- <ScrollView android:id="#+id/ScrollViewFriendScores" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbars="vertical">
<TableLayout android:id="#+id/TableLayout_FriendScores" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="*" />
</ScrollView>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
activity_main.xml contains
<?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="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/scroll" />
<HorizontalScrollView
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:layout_alignParentBottom="true" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/tabs_bg" />
</HorizontalScrollView>
</RelativeLayout>
</TabHost>
and java code is
TabHost tabHost = getTabHost();
TabSpec spec;
Intent intent;
//Home Tab
View view1 = LayoutInflater.from(MainActivity.this).inflate(R.layout.home, null);
intent = new Intent(MainActivity.this, Firstclass.class);
spec = tabHost.newTabSpec("HOME").setIndicator(view1)
.setContent(intent);
tabHost.addTab(spec);
//Calendar Tab
View view2 = LayoutInflater.from(MainActivity.this).inflate(R.layout.calendar_tab, null);
intent = new Intent(MainActivity.this, Calendar.class);
spec = tabHost.newTabSpec("CALENDAR").setIndicator(view2)
.setContent(intent);
tabHost.addTab(spec);
res/layout/activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TabHost
android:id="#+id/tabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"></TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffc916"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="This is tab 1" />
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#da8200"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="This is tab 2" />
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#5b89ff"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="This is tab 3" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
src/MainActivity.java
public class MainActivity extends AppCompatActivity {
TabHost tabHost;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost host = (TabHost)findViewById(R.id.tabHost);
host.setup();
//Tab 1
TabHost.TabSpec spec = host.newTabSpec("Tab One");
spec.setContent(R.id.tab1);
spec.setIndicator("Tab One");
host.addTab(spec);
//Tab 2
spec = host.newTabSpec("Tab Two");
spec.setContent(R.id.tab2);
spec.setIndicator("Tab Two");
host.addTab(spec);
//Tab 3
spec = host.newTabSpec("Tab Three");
spec.setContent(R.id.tab3);
spec.setIndicator("Tab Three");
host.addTab(spec);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
You can Follow these tutorials for help
Creating a tabbed UI with TabHost
Android Tab Layout Tutorial