Copy the TabHost menu at the bottom of Sina Weibo

Source: Internet
Author: User
Tags isearch

:

 

 


1.


Content of the main. xml file:

<? 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 = "0.0dip"
Android: layout_weight = "1.0"/>
<TabWidget
Android: id = "@ android: id/tabs"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_weight = "0.0"
Android: visibility = "gone"/>
<RadioGroup
Android: id = "@ + id/main_tab"
Android: background = "@ drawable/maintab_toolbar_bg"
Android: orientation = "horizontal"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: gravity = "center_vertical"
Android: layout_gravity = "bottom">
<RadioButton
Android: layout_marginTop = "2.0dip"
Android: text = "@ string/main_home"
Android: drawableTop = "@ drawable/icon_0000n"
Android: id = "@ + id/radio_button0"
Style = "@ style/main_tab_bottom"/>
<RadioButton
Android: layout_marginTop = "2.0dip"
Android: text = "@ string/main_news"
Android: drawableTop = "@ drawable/icon_2_n"
Android: id = "@ + id/radio_button1"
Style = "@ style/main_tab_bottom"/>
<RadioButton
Android: layout_marginTop = "2.0dip"
Android: text = "@ string/main_my_info"
Android: drawableTop = "@ drawable/icon_3_n"
Android: id = "@ + id/radio_button2"
Style = "@ style/main_tab_bottom"/>
<RadioButton
Android: layout_marginTop = "2.0dip"
Android: text = "@ string/menu_search"
Android: drawableTop = "@ drawable/icon_4_n"
Android: id = "@ + id/radio_button3"
Style = "@ style/main_tab_bottom"/>
<RadioButton
Android: layout_marginTop = "2.0dip"
Android: text = "@ string/more"
Android: drawableTop = "@ drawable/icon_5_n"
Android: id = "@ + id/radio_button4"
Style = "@ style/main_tab_bottom"/>
</RadioGroup>
</LinearLayout>
</TabHost>

 


2.


MainTabActivity. java file content:
Package com. jun. demo2;


Import android. app. TabActivity;
Import android. content. Intent;
Import android. OS. Bundle;
Import android. view. Window;
Import android. widget. RadioGroup;
Import android. widget. TabHost;
Import android. widget. RadioGroup. OnCheckedChangeListener;
Import android. widget. Toast;
Public class MainTabActivity extends TabActivity implements OnCheckedChangeListener {
Private RadioGroup mainTab;
Private TabHost tabhost;
Private Intent iHome;
Private Intent iNews;
Private Intent iInfo;
Private Intent iSearch;
Private Intent iMore;

@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
RequestWindowFeature (Window. FEATURE_NO_TITLE );
SetContentView (R. layout. main );
MainTab = (RadioGroup) findViewById (R. id. main_tab );
MainTab. setOnCheckedChangeListener (this );
Tabhost = getTabHost ();
// Initialize Intent here and set Intent to be uploaded to that Activity
// IHome = new Intent (this, HomeActivity. class );
// Tabhost. addTab (tabhost. newTabSpec ("iHome ")
//. SetIndicator (getResources (). getString (R. string. main_home), getResources (). getDrawable (R. drawable. icon_0000n ))
//. SetContent (iHome ));
//
// INews = new Intent (this, NewsActivity. class );
// Tabhost. addTab (tabhost. newTabSpec ("iNews ")
//. SetIndicator (getResources (). getString (R. string. main_news), getResources (). getDrawable (R. drawable. icon_2_n ))
//. SetContent (iNews ));
//
// IInfo = new Intent (this, MyInfoActivity. class );
// Tabhost. addTab (tabhost. newTabSpec ("iInfo ")
//. SetIndicator (getResources (). getString (R. string. main_my_info), getResources (). getDrawable (R. drawable. icon_3_n ))
//. SetContent (iInfo ));
//
// ISearch = new Intent (this, SearchActivity. class );
// Tabhost. addTab (tabhost. newTabSpec ("iSearch ")
//. SetIndicator (getResources (). getString (R. string. menu_search), getResources (). getDrawable (R. drawable. icon_4_n ))
//. SetContent (iSearch ));
//
// IMore = new Intent (this, MoreActivity. class );
// Tabhost. addTab (tabhost. newTabSpec ("iMore ")
//. SetIndicator (getResources (). getString (R. string. more), getResources (). getDrawable (R. drawable. icon_5_n ))
//. SetContent (iMore ));
}

@ Override
Public void onCheckedChanged (RadioGroup group, int checkedId ){
Switch (checkedId ){
Case R. id. radio_button0:
Toast. makeText (MainTabActivity. this, "button0", Toast. LENGTH_SHORT). show ();
Break;
Case R. id. radio_button1:
Toast. makeText (MainTabActivity. this, "button1", Toast. LENGTH_SHORT). show ();
Break;
Case R. id. radio_button2:
Toast. makeText (MainTabActivity. this, "button2", Toast. LENGTH_SHORT). show ();
Break;
Case R. id. radio_button3:
Toast. makeText (MainTabActivity. this, "button3", Toast. LENGTH_SHORT). show ();
Break;
Case R. id. radio_button4:
Toast. makeText (MainTabActivity. this, "button4", Toast. LENGTH_SHORT). show ();
Break;
}
}


}

 


3. string. xml file content:

<? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
<String name = "app_name"> SinaWeibo </string>
<String name = "main_home"> homepage </string>
<String name = "main_news"> Information </string>
<String name = "main_my_info"> my documents </string>
<String name = "menu_search"> Search </string>
<String name = "more"> more </string>

</Resources>

4. Contents of the drawables. xml file:

<? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
<Item type = "drawable" name = "transparent" >#00000000 </item>
</Resources>

5. Content of the dimens. xml file:

<? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
<Dimen name = "bottom_tab_padding_drawable"> 2.0dip </dimen>
<Dimen name = "bottom_tab_padding_up"> 5.0dip </dimen>
<Dimen name = "bottom_tab_font_size"> 10.0dip </dimen>
</Resources>

6. styles. xml file content:

<? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
<Style name = "main_tab_bottom">
<Item name = "android: textSize"> @ dimen/bottom_tab_font_size </item>
<Item name = "android: textColor"> # ffffffff </item>
<Item name = "android: ellipsize"> marquee </item>
<Item name = "android: gravity"> center_horizontal </item>
<Item name = "android: background"> @ drawable/home_btn_bg </item>
<Item name = "android: paddingTop"> @ dimen/bottom_tab_padding_up </item>
<Item name = "android: layout_width"> fill_parent </item>
<Item name = "android: layout_height"> wrap_content </item>
<Item name = "android: button"> @ null </item>
<Item name = "android: singleLine"> true </item>
<Item name = "android: drawablePadding"> @ dimen/bottom_tab_padding_drawable </item>
<Item name = "android: layout_weight"> 1.0 </item>
</Style>
</Resources>

7. Res/drawable file home_btn_bg.xml content: Set the color when the button is selected

<? Xml version = "1.0" encoding = "UTF-8"?>
<Selector
Xmlns: android = "http://schemas.android.com/apk/res/android">
<Item android: state_focused = "true" android: state_enabled = "true" android: state_pressed = "false" android: drawable = "@ drawable/home_btn_bg_s"/>
<Item android: state_enabled = "true" android: state_pressed = "true" android: drawable = "@ drawable/home_btn_bg_s"/>
<Item android: state_enabled = "true" android: state_checked = "true" android: drawable = "@ drawable/home_btn_bg_d"/>
<Item android: drawable = "@ drawable/transparent"/>
</Selector>


 

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.