Android TabHost Summary

Source: Internet
Author: User

TabHost is the container of the entire Tab, which consists of TabWidget and FrameLayout. TabWidget is the label of each tab, and FrameLayout is the tab content.

1. If we use extends TabAcitivty, like ListActivity, TabHost must be set to @ android: id/tabhost
2. You must set the android: id to @ android: id/tabs for TabWidget.
3. For FrameLayout, you must set android: id to @ android: id/tabcontent.
4. Refer to here: aspx "> http://blog.csdn.net/flowingflying/archive/2011/04/06/6304289.aspx

First, customize an xml file:
Java code
<? 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">
<FrameLayout
Android: id = "@ android: id/tabcontent"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: layout_weight = "1.0"
Android: paddingBottom = "53px"/>
<TabWidget
Android: id = "@ android: id/tabs"
Android: layout_alignParentBottom = "true"
Android: layout_width = "fill_parent"
Android: layout_height = "50px"
Android: visibility = "gone"
Android: layout_weight = "0.0"/>
<RadioGroup
Android: gravity = "center_vertical"
Android: orientation = "horizontal"
Android: id = "@ + id/main_radio"
Android: background = "@ drawable/radiogroup_background"
Android: layout_width = "fill_parent"
Android: layout_height = "50dip"
Android: layout_gravity = "bottom">
<RadioButton
Android: id = "@ + id/main_index_button"
Android: layout_marginTop = "1.0dip"
Android: layout_marginRight = "5dip"
Android: text = "@ string/main_name"
Android: drawableTop = "@ drawable/unistall"
Style = "@ style/main_tab_bottom"
Android: background = "@ drawable/radio_bg"/>
<RadioButton
Android: id = "@ + id/main_running_button"
Android: layout_marginTop = "1.0dip"
Android: layout_marginRight = "5dip"
Android: text = "@ string/run_manager_name"
Android: drawableTop = "@ drawable/unistall"
Style = "@ style/main_tab_bottom"
Android: background = "@ drawable/radio_bg"/>
<RadioButton
Android: id = "@ + id/main_uninstall_button"
Android: layout_marginTop = "1.0dip"
Android: text = "@ string/uninstall_manager_name"
Android: drawableTop = "@ drawable/unistall"
Style = "@ style/main_tab_bottom"
Android: background = "@ drawable/radio_bg"/>
</RadioGroup>
</LinearLayout>
</TabHost>

To display the tabHost at the bottom, set layout_gravity of RadioGroup to bottom, and set layout_weight of FrameLayout to 1, so that the RadioGroup can be stretched to the bottom. Style = "@ style/main_tab_bottom" defines the style file.

Next, initialize and add the tabhost in the activity:
Java code
TabHost = (TabHost) findViewById (android. R. id. tabhost );
TabHost. addTab (Constant. tabHost. newTabSpec ("Main ")
. SetIndicator (getString (R. string. main_name), null)
. SetContent (new Intent (this, Main. class )));
TabHost. addTab (Constant. tabHost. newTabSpec ("RunManager ")
. SetIndicator (getString (R. string. run_manager_name), null)
. SetContent (new Intent (this, RunManager. class )));
TabHost. addTab (Constant. tabHost. newTabSpec ("UninstallManager ")
. SetIndicator (getString (R. string. uninstall_manager_name), null)
. SetContent (new Intent (this, UninstallManager. class )));


Initialize each RadioButton and add setOnCheck to it

Related Article

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.