TabHost自定义图标的应用2010-12-24 20:31:05| 分类: android | 标签:android tabhost 自定义图片 字号:大中小 订阅
关于tabhost的应用已经很多了,今天我要写的是怎么改变tabhost的样式。
首先展示一下效果图:
public class MainActivity extends Activity {
//首先不要继承tabActivity,那样我们就不能自己创建tabhost了。
private TabHost mTabHost;
private View categoryView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTabHost = (TabHost) findViewById(R.id.tabhost);
mTabHost.setup();//创建tabhost
LayoutInflater inflater = LayoutInflater.from(this);
categoryView = inflater.inflate(R.layout.category, mTabHost.getTabContentView());
inflater.inflate(R.layout.tab2, mTabHost.getTabContentView());
inflater.inflate(R.layout.search, mTabHost.getTabContentView());
mTabHost.addTab(mTabHost.newTabSpec("t1").setIndicator("")
.setContent(R.id.LinearLayout01));
mTabHost.addTab(mTabHost.newTabSpec("t2").setIndicator("")
.setContent(R.id.FrameLayout02));
mTabHost.addTab(mTabHost.newTabSpec("t3").setIndicator("")
.setContent(R.id.LinearLayout03));
TabWidget tw = mTabHost.getTabWidget();
//tw.setStripEnabled(false);
//设置tabhost的图片
mTabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.category_bottom);
mTabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.buycar_bottom);
mTabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.search_bottom);
}
}
main.xml源码,一定要注意每个控件的名称
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- android:paddingBottom="50dip" 避免覆盖TabWidget -->
<FrameLayout android:id="@android:id/tabcontent" android:paddingBottom="50dip"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</FrameLayout>
<TabWidget android:id="@android:id/tabs" android:layout_gravity="bottom"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
</TabHost>
分享到:
相关推荐
现今很流行的 TabHost的各种实现方式的代码
TabHost中填充自定义ListView
tabhost中嵌套一个tabhost。
TabHost的使用方法,适合初学者,适合课堂讲授实现模拟显示未接来电、已接来电和拨出电话的选项卡。
TabHost+ViewPager实现滑动tabhost, viewPager;tabhost;滑动;源码
Android 嵌套TabHost示例. 两层TabHost嵌套,实现的效果类似网页上的二级菜单栏。
tabhost标签页面简单实现,这是学习android初期做的demo,
tabhost页面跳转需要用到的tabhost单例模式小例子,也有tabhost底部的布局
Android TabHost TabActivity TabHost的简单使用
Android TabHost实现屏幕UI窗口的TAB切换功能,实现的过程:声明TabHost对象、取得TabHost对象,为TabHost添加标签,新建一个newTabSpec(newTabSpec),设置其标签和图标(setIndicator),设置内容(setContent),然后...
ViewPager和Tabhost结合,可滑动的tabhost源代码,是一个很不错的Android源码,有兴趣的伙伴们抽时间可以看一下把
TabHost分页简单应用,以及解决TabHost下面白线问题.
android Tabhost使用Demo
1、底部tabhost嵌套顶部tabhost. 2、顶部tabhost,嵌套listview。 3、顶部tabhost子tab选项仿网易新闻功能,可以滑动,每一个对应一个listvie
Android TabHost TabWidget 切换卡
android-->tabHost 源码
androidTabhost的使用实例代码,仅供参考
TabHost实现底部菜单, 底部菜单选项卡主要是通过TabHost和RadioGroup实现
android TabHost(标签)的使用 简单实例。
TabHost布局的框架,点击button按钮切换页面、随即更改字体颜色和背景图片。