TabHost配合Radio按钮 简单使用
使用TabHost 可以在一个屏幕间进行不同版面的切换
一、继承TabActivity
示例
public class MainActivity extends TabActivity {
private TabHost tabHost;
private RadioGroup radioGroup;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
radioGroup = (RadioGroup)findViewById(R.id.main_radio);
tabHost = getTabHost();
//添加选项卡
tabHost.addTab(tabHost.newTabSpec("tab_test1").setIndicator("TAB ONE").setContent(new Intent(this,TaboneActivity.class)));
tabHost.addTab(tabHost.newTabSpec("tab_test2").setIndicator("TAB_TWO").setContent(new Intent(this, TabtwoActivity.class)));
//初始选中
tabHost.setCurrentTabByTag("tab_test2");
//设置为默认选中
radioGroup.check(R.id.strollbtn);
//radio按钮事件
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.recommendbtn:
tabHost.setCurrentTabByTag("tab_test1");
break;
case R.id.strollbtn:
tabHost.setCurrentTabByTag("tab_test2");
break;
}
}
} );
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabHost android:id="@android:id/tabhost" //id android 默认
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--注意 设置此LinearLayout时,选项卡在底部,如去提,选项卡在屏幕顶部-->
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<FrameLayout android:id="@android:id/tabcontent" //id android 默认
android:layout_width="fill_parent" android:layout_height="0.0dip"
android:layout_weight="1.0"/>
<!--注意切记 android:visibility="gone" 时,隐藏系统提供的选项卡,方便设计自定义选项卡-->
<TabWidget android:id="@android:id/tabs" //android 默认
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:visibility="gone" android:layout_weight="0.0"/>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="#ff919191"
android:paddingTop="1px">
<!-- 自定义radio组件-->
<RadioGroup android:gravity="center_vertical"
android:layout_gravity="bottom" android:orientation="horizontal"
android:id="@+id/main_radio" android:background="@color/skin_green"
android:layout_width="fill_parent" android:layout_height="50dp">
<RadioButton android:id="@+id/recommendbtn"
android:tag="recommendbtn" style="@style/style_recommendbtn" />
<RadioButton android:id="@+id/strollbtn" android:tag="strollbtn"
style="@style/style_strollbtn" />
<RadioButton android:id="@+id/specialbtn" android:tag="specialbtn"
</RadioGroup>
</LinearLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
TaboneActivity
public class TaboneActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_one);
}
}
layout_one.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linear1"
android:orientation="vertical">
<TextView android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="第一个页面"></TextView>
<LinearLayout android:id="@+id/content"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1.0" android:background="@color/background">
</LinearLayout>
</LinearLayout>
相关推荐
android TabHost(标签)的使用 简单实例。
Android TabHost TabActivity TabHost的简单使用
android 页卡效果,用tabhost实现最简单的页卡效果
Android编程之Intent_TabHost源码演示,自定义的Tabhost(内含源码),学习制作Android软件的TAB标签界面,在电脑上已经很流行的功能,Android手机上当然不能少,这个TabHost源码相对简单些,是JAVA转学Android比较...
Android tabhost菜单,一个简单的列子
tabhost嵌套滑动菜单,使用ValueAnimator简单实现
Android TabHost TabActivity TabHost的简单使用
代码很简单注释非常详细,下下来就可以直接使用,希望可以帮助有需要的人.
一个很简单的滑动分页的tab小应用,利用ViewFlipper来实现分布效果,利用GestureDetector来实现手势监听...
百度用一个CustomTabHost.java来实现底部TabHost点击效果的,很漂亮,点击Tab的时候文字会上跑,图片会从底部跑出来的一个小动画。...我用自己的方法逆袭了他的CustomTabHost,感觉用起来比它的好用,而且简单不少!
简单的例子 能够运行流畅 是想手机一样的 通过手指左右滑动切换tabhost
主要介绍了Android编程实现设置TabHost当中字体的方法,涉及Android针对TabHost属性操作的相关技巧,非常简单实用,需要的朋友可以参考下
简单的android选项卡Tab菜单TabHost(一)同一Activity上实现
tabhost标签页面简单实现,这是学习android初期做的demo,
android开发中用tabhost+radiogroup实现底部菜单栏功能,和一个简单的布局应用,里面有三个activity的切换,能用于一般开发的框架搭建
自定义tabhost实现activity 的跳转 界面比较简单 但功能都实现了
使用TabHost仿新浪微博的底部功能实现,内有源码和图片,可以直接运行,附有详细注释
在工作中又很多需求都不是android系统自带的控件可以达到效果的,内置的TabHost就是,只能达到简单的效果 ,所以这个时候就要自定义控件来达到效果:这个效果就是: 使用自定义RadioButton和ViewPager实现TabHost带...
一个简单的实现例子,底部TabHost,内部加载Activity。