加入收藏 | 设为首页 | 会员中心 | 我要投稿 济南站长网 (https://www.0531zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

Android TabHost 动态修改图标或者动态革新标题

发布时间:2021-11-25 20:09:46 所属栏目:教程 来源:互联网
导读:遇到这个问题的时候,说实话,刚开始也没有想到这个方法。那时客户需要实现在TabHost标题上动态显示从数据库获取的个数。起初这样思考的,从数据库获取个数是非常简单,但是要把获取的个数显示在TabHost标题,思前恋后,想用Handler来异步实现消息传递。最终
遇到这个问题的时候,说实话,刚开始也没有想到这个方法。那时客户需要实现在TabHost标题上动态显示从数据库获取的个数。起初这样思考的,从数据库获取个数是非常简单,但是要把获取的个数显示在TabHost标题,思前恋后,想用Handler来异步实现消息传递。最终也没有解决掉。也许也有很多的朋友和我遇到同样棘手的问题吧。
 
把我解决的方法和大家分享下吧。
 
如果将图标或者标题的变量设置为全局变量,你们应该知道我的目的吧。也就是为了在这个类不断的进行赋值。
 
先来简单的认识下TabHost吧。理论我就不多说了,你们看的话也很累,还是直接代码贴出来看看就一目了然了。
 
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:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <TextView
                android:id="@+id/textview1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="this is a tab" />
            <TextView
                android:id="@+id/textview2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="this is another tab" />
            <TextView
                android:id="@+id/textview3"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="this is a third tab" />
     </FrameLayout>
    </LinearLayout>
</TabHost>
 
说明一下红色的标注,我们应该不可以改变的吧。

(编辑:济南站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读