"Original" Android--tabhost custom tab+ Bottom implementation +intent switch content

Source: Internet
Author: User

1, implement Tabhost custom format, then only display the background and text, preview: (bottom bar shown)

(Picture variant)

2,xml Configuration

XML configuration for Activity_user
1 <Tabhostxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:id= "@+id/tabhost"4 Android:layout_width= "Match_parent"5 Android:layout_height= "Match_parent"6 Android:layout_alignparentbottom= "true"7 Tools:context= "${relativepackage}.${activityclass}" >8   9     <LinearLayoutTen         Android:id= "@+id/linearlayout1" One Android:layout_width= "Fill_parent" A Android:layout_height= "Fill_parent" - android:orientation= "vertical"  -         > the           <TextView -             Android:id= "@+id/user_welcome" - Android:layout_width= "Match_parent" - Android:layout_height= "15DP" + Android:background= "#56a692" - Android:textcolor= "#fff" + android:gravity= "Bottom" A android:textsize= "12SP"/> at  -         <Framelayout -             Android:id= "@android: Id/tabcontent" - Android:layout_width= "Fill_parent" - Android:layout_height= "0DP" - Android:layout_weight= "4.25" > in              <!--Furnishings - -         </Framelayout> to  +         <Tabwidget -             Android:id= "@android: Id/tabs" the Android:layout_width= "Match_parent" * Android:layout_height= "50DP" $ Android:background= "#EECFA1" >Panax Notoginseng         </Tabwidget> -  the     </LinearLayout> +  A </Tabhost>

The following is: Configuration of the Lost.xml

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:layout_width= "80DP"4 Android:layout_height= "80DP"5 android:orientation= "vertical">6         <TextViewAndroid:id= "@+id/tab_label2"    7 Android:layout_width= "Fill_parent"  8 Android:layout_height= "Wrap_content"  9 android:gravity= "Center"Ten Android:textcolor= "#FFF"   One Android:textstyle= "Bold"   A Android:background= "@drawable/tablost"/>  -  - </LinearLayout>

2, the implementation of the main interface

1  Packagecom.example.dbtest;2 3 ImportAndroid.annotation.SuppressLint;4 Importandroid.app.Activity;5 ImportAndroid.app.LocalActivityManager;6 Importandroid.content.Intent;7 ImportAndroid.os.Bundle;8 ImportAndroid.view.LayoutInflater;9 ImportAndroid.view.View;Ten ImportAndroid.widget.TabHost; One ImportAndroid.widget.TextView; A  -  -@SuppressWarnings ("Deprecation") the@SuppressLint ("Inflateparams") -  Public classUserextendsActivity { -  -     PrivateTextView tv_welcome; +     Privatetabhost tab; -      +@SuppressLint ("Inflateparams") A @Override at     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_user); -Tv_welcome=(TextView) Findviewbyid (r.id.user_welcome); -         //Set Title -Bundle bundle= This. Getintent (). Getextras (); inString username=bundle.getstring ("name"); -Tv_welcome.settext ("Welcome!" "+username);  to         //adding groupactivity is necessary to implement intent +Localactivitymanager groupactivity =NewLocalactivitymanager ( This,false); - groupactivity.dispatchcreate (savedinstancestate); the  *  $         Panax NotoginsengView Mestab = (view) Layoutinflater.from ( This). Inflate (R.layout.lost,NULL);  -TextView mes =(TextView) Mestab.findviewbyid (R.ID.TAB_LABEL2);  theMes.settext ("Release"); +  AView Losttab = (view) Layoutinflater.from ( This). Inflate (R.layout.lost,NULL);  theTextView lost =(TextView) Losttab.findviewbyid (R.ID.TAB_LABEL2);  +Lost.settext ("Lost"); -  $View Foundtab = (view) Layoutinflater.from ( This). Inflate (R.layout.lost,NULL);  $TextView found =(TextView) Foundtab.findviewbyid (R.ID.TAB_LABEL2);  -Found.settext ("Found"); -  theView Tooltab = (view) Layoutinflater.from ( This). Inflate (R.layout.lost,NULL);  -TextView tool =(TextView) Tooltab.findviewbyid (R.ID.TAB_LABEL2); WuyiTool.settext ("Search"); the  -tab=(tabhost) Findviewbyid (r.id.tabhost); Wu //This quote groupactivity - Tab.setup (groupactivity); About  $  - //The following are jumps to different activity -Intent intent=NewIntent (User. This, User_center.class); -Tab.addtab (Tab.newtabspec ("Mes")). Setindicator (Mestab). SetContent (intent));  A  +Intent intent1=NewIntent (User. This, User_lost.class); theTab.addtab (Tab.newtabspec ("Lost"). Setindicator (Losttab). SetContent (Intent1));  -  $Intent intent2=NewIntent (User. This, User_found.class); theTab.addtab (Tab.newtabspec ("found"). Setindicator (Foundtab). SetContent (Intent2));  the  theIntent intent3=NewIntent (User. This, User_tool.class); theTab.addtab (Tab.newtabspec ("tool"). Setindicator (Tooltab). SetContent (Intent3));  -        in          the     } the      About      the}

3, File analysis

4, picture yourself quote!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.