Android Implementation Bottom Tabhost

Source: Internet
Author: User

First say the layout file, as follows: Using android:layout_alignparentbottom= "true" to achieve the bottom display

<?xmlversion="1.0"encoding="utf-8"?>

< TabHost xmlns:android = "http://schemas.android.com/apk/res/android"      android:id = "@android:id/tabhost"      android:orientation = "vertical"      android:layout_width = "fill_parent"      android:layout_height = "fill_parent" >      < RelativeLayout          android:background = "@drawable/g"          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"          android:layout_alignParentBottom = "true" >      </ TabWidget >      < FrameLayout android:id = "@android:id/tabcontent"          android:layout_width = "fill_parent"          android:layout_height = "fill_parent" >          < RelativeLayout android:id = "@+id/tabFirst"              android:layout_width = "fill_parent"              android:layout_height = "fill_parent"              android:orientation = "vertical" >          < AnalogClock              android:id = "@+id/widget31"              android:layout_width = "wrap_content"              android:layout_height = "wrap_content"              android:layout_centerInParent = "true" >          </ AnalogClock >          </ RelativeLayout >>          < RelativeLayout android:id = "@+id/tabSecond"              android:layout_width = "fill_parent"              android:layout_height = "fill_parent"              android:orientation = "vertical" >              < DigitalClock                  android:layout_centerInParent = "true"                  android:layout_width = "wrap_content"                  android:layout_height = "wrap_content" >              </ DigitalClock >          </ RelativeLayout >      </ FrameLayout >      </ RelativeLayout > </ TabHost >Here is the main program code, comments written in more detail, there is no more explanation package com.cloay; import android.app.TabActivity; import android.graphics.Color; import android.os.Bundle; import android.widget.TabHost; import android.widget.TabHost.OnTabChangeListener; import android.widget.Toast; public class TabTestActivity  extends TabActivity {      TabHost tabHost;      @Override      public void onCreate(Bundle savedInstanceState) {          super .onCreate(savedInstanceState);          setContentView(R.layout.main);          //获取TabHost对象          tabHost = getTabHost();   //        tabHost.setup();          //新建一个newTabSpec,设置标签和图标(setIndicator),设置内容(setContent)          tabHost.addTab(tabHost.newTabSpec( "Test one" ).setIndicator( "" ,getResources().getDrawable(android.R.drawable.ic_menu_call)).setContent(R.id.tabFirst));          tabHost.addTab(tabHost.newTabSpec( "Test two" ).setIndicator( "" ,getResources().getDrawable(android.R.drawable.ic_menu_camera)).setContent(R.id.tabSecond));          //设置TabHost的背景颜色          tabHost.setBackgroundColor(Color.argb( 150 , 22 , 70 , 150 ));          //设置TabHost的背景图片资源 //      tabHost.setBackgroundResource(R.drawable.bg);          //设置当前现实哪一个标签          tabHost.setCurrentTab( 0 );    //0为标签ID          //标签切换处理,用setOnTabChangedListener            tabHost.setOnTabChangedListener( new OnTabChangeListener(){              public void onTabChanged(String tabId){                  Toast.makeText(TabTestActivity. this "This is a Test!" , Toast.LENGTH_LONG).show();              }          });      } }

Android Implementation Bottom Tabhost

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.