采用TabHost和RadioButton实现页面导航效果
来源:互联网 发布:淘宝女装销量 编辑:程序博客网 时间:2024/04/30 20:41
实现的效果不解释,主要是记录一下代码
先看一下xml布局:
<?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:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <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:background="@drawable/maintab_toolbar_bg" android:visibility="gone" /> <RadioGroup android:id="@id/main_radio" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:background="@drawable/maintab_toolbar_bg" android:gravity="center_vertical" android:orientation="horizontal" > <RadioButton android:id="@id/radio_contact" style="@style/main_tab_bottom" android:drawableTop="@drawable/main_tab_contact_checked" android:text="@string/radio_contact" /> <RadioButton android:id="@id/radio_calllist" style="@style/main_tab_bottom" android:layout_marginTop="0dip" android:layout_marginBottom="0dip" android:drawableTop="@drawable/main_tab_calllist_normal" android:text="@string/radio_calllist" /> <RadioButton android:id="@id/radio_sms" style="@style/main_tab_bottom" android:layout_marginTop="0dip" android:layout_marginBottom="0dip" android:drawableTop="@drawable/main_tab_sms_normal" android:text="@string/radio_sms" /> <RadioButton android:id="@id/radio_setting" style="@style/main_tab_bottom" android:layout_marginTop="0dip" android:layout_marginBottom="0dip" android:drawableTop="@drawable/nav_menu_me" android:text="@string/radio_setting" /> </RadioGroup> </LinearLayout></TabHost>
二、MainTabActivity
package com.gs.app.main;import android.app.TabActivity;import android.content.Intent;import android.os.Bundle;import android.view.Window;import android.widget.CompoundButton;import android.widget.CompoundButton.OnCheckedChangeListener;import android.widget.RadioButton;import android.widget.TabHost;import com.gs.Appblue.R;import com.gs.app.contact.ContactsListActivity;import com.gs.app.contact.RecentCallsListActivity;import com.gs.app.setting.Setting;import com.gs.app.sms.ActSMSList;public class MainTabActivity extends TabActivity implementsOnCheckedChangeListener {private TabHost mTabHost;private Intent mContactIntent;private Intent mCallLogIntent;private Intent mSmsIntent;private Intent mSetIntent;public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.main_tab);this.mContactIntent = new Intent(this, ContactsListActivity.class);this.mCallLogIntent = new Intent(this, RecentCallsListActivity.class);this.mSmsIntent = new Intent(this, ActSMSList.class);this.mSetIntent = new Intent(this, Setting.class);((RadioButton) findViewById(R.id.radio_contact)).setOnCheckedChangeListener(this);((RadioButton) findViewById(R.id.radio_calllist)).setOnCheckedChangeListener(this);((RadioButton) findViewById(R.id.radio_sms)).setOnCheckedChangeListener(this);((RadioButton) findViewById(R.id.radio_setting)).setOnCheckedChangeListener(this);setupIntent();}private void setupIntent() {this.mTabHost = getTabHost();TabHost localTabHost = this.mTabHost;localTabHost.addTab(buildTabSpec("A_TAB", R.string.radio_contact,R.drawable.main_tab_contact_normal, this.mContactIntent));localTabHost.addTab(buildTabSpec("B_TAB", R.string.radio_calllist,R.drawable.main_tab_calllist_normal, this.mCallLogIntent));localTabHost.addTab(buildTabSpec("C_TAB", R.string.radio_sms,R.drawable.main_tab_sms_normal, this.mSmsIntent));localTabHost.addTab(buildTabSpec("D_TAB", R.string.radio_setting,R.drawable.main_tab_setting_normal, this.mSetIntent));localTabHost.setCurrentTab(0);}@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {if (isChecked) {switch (buttonView.getId()) {case R.id.radio_contact:this.mTabHost.setCurrentTabByTag("A_TAB");break;case R.id.radio_calllist:this.mTabHost.setCurrentTabByTag("B_TAB");break;case R.id.radio_sms:this.mTabHost.setCurrentTabByTag("C_TAB");break;case R.id.radio_setting:this.mTabHost.setCurrentTabByTag("D_TAB");break;}}}private TabHost.TabSpec buildTabSpec(String tag, int resLabel, int resIcon,final Intent content) {return this.mTabHost.newTabSpec(tag).setIndicator(getString(resLabel),getResources().getDrawable(resIcon)).setContent(content);}}
0 0
- 采用TabHost和RadioButton实现页面导航效果
- Android小项目之采用TabHost和RadioButton实现底部页面导航
- Android TabHost + RadioButton实现Tab导航栏
- RadioButton和ViewPager实现页面切换效果
- fragment和radiobutton做出类tabhost效果
- 使用自定义RadioButton和ViewPager实现TabHost效果和带滑动的页卡效果。
- RadioButton + selector实现Tab导航效果
- Fragment+RadioButton实现点击切换页面效果
- Fragment+RadioButton实现点击切换页面效果
- tabHost研究二——利用Radiobutton嵌套在RadioGroup实现TabHost效果
- 关于Fragment、Tabhost和FragmentPagerAdapter来实现导航栏的效果
- 使用TabHost和FrameLayout实现导航
- Fragment 和RadioButton 实现底部导航拦
- Fragment 和RadioButton 实现底部导航拦
- 页面导航效果实现总结
- Android 导航条效果实现(一) TabActivity+TabHost
- 使用TabHost和ViewPager实现页面切换
- [基础学习]ViewPager和Fragment与RadioButton结合做一个类似Tabhost的效果
- 词性标注
- static 作用总结(c/c++)
- android layout_weight
- STM8S TIM4库函数应用
- Eclipse去除js(JavaScript)验证错误
- 采用TabHost和RadioButton实现页面导航效果
- R common function
- 关于Ubuntu下的PDF阅读器
- BP 算法 (Back-propagation Algorithm) 之较直观的解释
- aoeiu鱼
- User Profile Synchronization Service–Hangs on Starting (I fixed it!) 用户配置文件同步服务卡在“正在启动”状态
- hadoop配置心得
- 嵌入式 SDL把字符串转位图示例代码
- 利用互联网充分调动人的积极性解决各个领域的问题是互联网发展被忽略的另一个方向。