android TabHost的一种用RadioButton来实现的切换
来源:互联网 发布:智能小区门禁软件 编辑:程序博客网 时间:2024/05/23 01:29
Layout:
<?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="0dip" android:layout_weight="1"/> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0" android:visibility="gone" /> <RadioGroup android:orientation="horizontal" android:id="@+id/main_radio"android:layout_width="fill_parent" android:layout_height="wrap_content"android:layout_gravity="bottom" android:gravity="center_vertical"android:background="@drawable/maintab_toolbar_bg"><RadioButton android:drawableTop="@drawable/icon_1_n" android:tag="radio_button0"android:layout_marginTop="2dp"android:text="@string/main_home"style="@style/main_tab_bottom" /><RadioButton android:drawableTop="@drawable/icon_2_n" android:tag="radio_button1"android:layout_marginTop="2dp"android:text="@string/main_news"style="@style/main_tab_bottom" /><RadioButton android:drawableTop="@drawable/icon_3_n" android:tag="radio_button2"android:layout_marginTop="2dp"android:text="@string/main_my_info"style="@style/main_tab_bottom" /><RadioButton android:drawableTop="@drawable/icon_4_n" android:tag="radio_button3"android:layout_marginTop="2dp"android:text="@string/menu_search"style="@style/main_tab_bottom" /><RadioButton android:drawableTop="@drawable/icon_5_n"android:tag="radio_button4"android:layout_marginTop="2dp"android:text="@string/more"style="@style/main_tab_bottom" /></RadioGroup></LinearLayout></TabHost>
这样来写activity:
public class WeiboMainTabActivity extends TabActivity implements OnCheckedChangeListener{Intent animationTest; Intent DetailShopActivity;Intent EditTextExample;Intent MainActivity;private RadioButton[] mRadioButtons;private TabHost mHost;boolean mTabSetup;public static int mMode = 0;public static final String MODE_KEY = "MODE_KEY";public static final int MODE_HOME = 0;/* * public static final int MODE_MESSAGE = 1; public static final int * MODE_COMMENT = 2; public static final int MODE_AT = 3; */public static final int MODE_MYBLOG = 4;public static final int MODE_FAVORITE = 5;// public static final int MODE_SEARCH = 9;public static final int MODE_USER = 10;public static final int MODE_TOPIC = 11;private static final int OEM_FACTORY = 0;private static final int OEM_SONY_ERICSSON = 1;public static final int SWITCHUSER = 0;private static final int DIALOG_ALERT_ATTENTION_OFFICAL = 100;public static final int MODE_DEFAULT = -1;public static final int MODE_MBLOG = 0;public static final int MODE_USERINFO = 1;public static final int MODE_SEARCH = 2;public static final int MODE_MORE = 3;public static final int MODE_COMMENT = 4;public static final int MODE_AT = 5;public static final int MODE_MESSAGE = 6;public static final int MODE_GRASSROOT = 7;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.maintabs);animationTest = new Intent(this,AnimationTest.class);DetailShopActivity = new Intent(this,DetailShopActivity.class);EditTextExample = new Intent(this,EditTextExample.class);MainActivity = new Intent(this,MainActivity.class);mHost = getTabHost();initRadios();setupIntent();}private void setupIntent() {mHost.clearAllTabs();mHost.addTab(mHost.newTabSpec("mblog_tab").setIndicator(getString(R.string.main_home),getResources().getDrawable(R.drawable.icon_1)).setContent(animationTest));mHost.addTab(mHost.newTabSpec("message_tab").setIndicator(getString(R.string.main_message),getResources().getDrawable(R.drawable.icon_2)).setContent(DetailShopActivity));mHost.addTab(mHost.newTabSpec("userinfo_tab").setIndicator(getString(R.string.user_info),getResources().getDrawable(R.drawable.icon_3)).setContent(EditTextExample));mHost.addTab(mHost.newTabSpec("search_tab").setIndicator(getString(R.string.menu_search),getResources().getDrawable(R.drawable.icon_4)).setContent(DetailShopActivity));mHost.addTab(mHost.newTabSpec("more_tab").setIndicator(getString(R.string.more),getResources().getDrawable(R.drawable.main_more_icon)).setContent(animationTest));// mHost.addTab(mHost.newTabSpec("userinfo_tab").setIndicator(getString(R.string.menu_search),// getResources().getDrawable(R.drawable.icon_5)).setContent(mSearchIntent));mTabSetup = true;}private void initRadios() {RadioGroup group = (RadioGroup) findViewById(R.id.main_radio);final int RADIO_COUNT = 5;mRadioButtons = new RadioButton[RADIO_COUNT];for (int i = 0; i < RADIO_COUNT; i++) {mRadioButtons[i] = (RadioButton) group.findViewWithTag("radio_button" + i);mRadioButtons[i].setOnCheckedChangeListener(this);}}@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {if (isChecked && mHost != null) {if (buttonView == mRadioButtons[0]) {mMode = MODE_MBLOG;mHost.setCurrentTabByTag("mblog_tab");}else if (buttonView == mRadioButtons[1]) {if (!(mMode == MODE_AT || mMode == MODE_COMMENT || mMode == MODE_MESSAGE)) {mMode = MODE_AT;}mHost.setCurrentTabByTag("message_tab");}else if (buttonView == mRadioButtons[2]) {mMode = MODE_USERINFO;mHost.setCurrentTabByTag("userinfo_tab");}else if (buttonView == mRadioButtons[3]) {mMode = MODE_SEARCH;mHost.setCurrentTabByTag("search_tab");}else if (buttonView == mRadioButtons[4]) {mMode = MODE_MORE;mHost.setCurrentTabByTag("more_tab");}}}}
效果图:
0 0
- android TabHost的一种用RadioButton来实现的切换
- Android使用Fragment来实现TabHost的功能(解决切换Fragment状态不保存)
- 用Fragment实现tabhost的切换效果
- Android TabHost TabWidget切换卡的实现应用
- android TabHost+Fragment实现页面切换时遇到的问题
- TabHost的实现过程中RadioButton的选中圆圈删除
- Android 使用GridView来实现类似RadioButton的多行单选功能
- Android 使用GridView来实现类似RadioButton的多行单选功能
- Android用tabhost实现 界面切换,每个界面为一个独立的activity
- Android TabHost + RadioButton实现Tab导航栏
- android的RadioButton切换不同的fragment
- tabhost的一种用法
- RadioButton实现底部切换的菜单
- Android中TabHost切换不同的Activity
- Android:TabHost实现Tab切换
- Android:TabHost实现Tab切换
- tabhost实现android菜单切换
- Android:TabHost实现Tab切换
- 初学一天Objective-C的总结
- C++高精度大整数模板
- POJ1979 - Red and Black
- HDU 1548 A strange lift
- hdu 1143 Tri Tiling
- android TabHost的一种用RadioButton来实现的切换
- POJ 3020 Antenna Placement ,二分图的最小路径覆盖
- eclipse 如何用 link 方式安装 SVN 插件
- zoj 1058 Currency Exchange
- Hometask--LCA
- acdream 1064 完美数 数位dp
- 求循环变换序列中逆序对的个数
- HTML学习之HTML常用标签(一)
- LeetCode Single Number