I have done this before, but for the life of me I cant remember. I'm wanting a tab with in a tab. This is my mainactivity
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost = getTabHost();
TabHost.TabSpec Login = tabHost.newTabSpec("Login");
// setting Title and Icon for the Tab
Login.setIndicator("", getApplicationContext().getResources().getDrawable(R.drawable.tab1));
Intent LoginIntent = new Intent(this, Tab1Activity.class);
LoginIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Login.setContent(LoginIntent);
// Tab for jobs
TabHost.TabSpec Jobs = tabHost.newTabSpec("Jobs");
Jobs.setIndicator("", getApplicationContext().getResources().getDrawable(R.drawable.tab2));
Intent JobsIntent = new Intent(this, Tab2Activity.class);
JobsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Jobs.setContent(JobsIntent);
TabHost.TabSpec Jobs3 = tabHost.newTabSpec("Jobs3");
Jobs3.setIndicator("", getApplicationContext().getResources().getDrawable(R.drawable.tab3));
Intent JobsIntent3 = new Intent(this, Tab3Activity.class);
JobsIntent3.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Jobs3.setContent(JobsIntent3);
// Adding all TabSpec to TabHost
tabHost.addTab(Login);
tabHost.addTab(Jobs);
tabHost.addTab(Jobs3);
}
This is Tab2Activity.java
public class Tab2Activity extends TabActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tab2);
/////////////////////////
TabHost tabHost2 = getTabHost();
TabHost.TabSpec Gmapped = tabHost2.newTabSpec("InnerTabs");
// setting Title and Icon for the Tab
Gmapped.setIndicator("", getApplicationContext().getResources().getDrawable(R.drawable.tab3));
Intent GmappedIntent = new Intent(this, Tab3Activity.class);
GmappedIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Gmapped.setContent(GmappedIntent);
tabHost2.addTab(Gmapped);
}
and Tab2.xml
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:gravity="center"
android:background="#332b2b"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<Button
android:id="@+id/veganfestival"
android:text="Aberdeen"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/buttonshape"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
/>
<TextView
android:id="@+id/blank"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textColor="#ffffff" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#6f844a" />
<TextView
android:id="@+id/venue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Venue"
android:textSize="20dp"
android:textColor="#ffffff" />
<TextView
android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address"
android:textSize="20dp"
android:textColor="#ffffff" />
<TextView
android:id="@+id/city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="City"
android:textSize="20dp"
android:textColor="#ffffff" />
<TextView
android:id="@+id/postcode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Postcode"
android:textSize="20dp"
android:textColor="#ffffff" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#6f844a" />
<TextView
android:id="@+id/Vdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date"
android:textSize="20dp"
android:textColor="#ffffff" />
<TextView
android:id="@+id/Vtime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time"
android:textSize="20dp"
android:textColor="#ffffff" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#6f844a" />
<TextView
android:id="@+id/blankagain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textColor="#ffffff" />
<Button
android:id="@+id/nav"
android:text="Take Me There"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/buttonshape"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
/>
</LinearLayout>
</ScrollView>
I have not been developing long, but I understand I need to at TabHost to Tab2.xml, but unsure were. Could someone help out.
If you want an advice, use TabLayout
instead, is more easy:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.