有时候我们的tabhost并不需要贴图,所以这个时候就必须把文字居中显示和设置大小了,代码如下

setContentView(R.layout.home_vzo_tabhost);
        
        tabHost = getTabHost();
        tabWidget = tabHost.getTabWidget();
        
        TabHost.TabSpec spec;
        
        Intent intent;
        //indicator指示器
        intent = new Intent(this,HomeVzoBasicInfoActivity.class);  //把值传给启动的界面
        //名字;要显示的字符;设置动画
        spec = tabHost.newTabSpec("a1").setIndicator(getResources().getString(R.string.baseInfo))
                .setContent(intent);//设置一个Acitivity
        
        tabHost.addTab(spec);
        
        intent = new Intent(this,HomeVzoContentActivity.class);
        
        spec = tabHost.newTabSpec("a2").setIndicator(getResources().getString(R.string.myPull))
                .setContent(intent);
        tabHost.setOnTabChangedListener(this);
        tabHost.addTab(spec);
        for (int i =0; i < tabWidget.getChildCount(); i++) {  
            //修改Tabhost高度和宽度
//            tabWidget.getChildAt(i).getLayoutParams().height = 30;  
//            tabWidget.getChildAt(i).getLayoutParams().width = 65;
            //修改显示字体大小
            TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
            tv.setTextSize(18);
            RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) tv.getLayoutParams();
            params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0); //取消文字底边对齐
            params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); //设置文字居中对齐
        }
        tabHost.setCurrentTab(0);

配置文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    
        <LinearLayout
        style="@style/vzo_ll">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"
        android:layout_marginTop="20dip"
        android:layout_marginBottom="15dip"
        android:layout_marginLeft="15dip"/>
        <FrameLayout
            android:orientation="horizontal"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="10dp"
            android:background="@drawable/item_bg_whilt"
            android:layout_marginTop="20dip"
            android:layout_marginBottom="15dip"
            android:layout_marginRight="10dip"
            android:layout_weight="1">
            <TextView
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="@string/neckName"
                 android:gravity="center"
                 android:layout_marginLeft="5dip"
                 android:layout_marginRight="5dip"
                 android:drawableRight="@drawable/tab_sms_selected"
                 android:layout_gravity="left|center_vertical"/>
            <TextView
                 android:id="@+id/neckName"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:text="@string/neckName"
                 android:gravity="center"
                 android:textColor="#558800"
                 android:layout_marginLeft="5dip"
                 android:layout_gravity="center"
                 android:textAppearance="?android:attr/textAppearanceLarge"/>
        </FrameLayout>
    </LinearLayout>
    
    <TabHost
        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" >
            
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:tabStripEnabled="false"
                android:animateLayoutChanges="true">
            </TabWidget>
            
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:padding="5dp" >
            </FrameLayout>
            
        </LinearLayout>
    </TabHost>

</LinearLayout>

修改Tabhost样式和字体大小和居中显示的更多相关文章

  1. 修改XtraMessageBox的内容字体大小

    修改XtraMessageBox的内容字体大小 public static DialogResult Show(UserLookAndFeel lookAndFeel, IWin32Window ow ...

  2. ggplot2画histogram(坐标轴刻度值字体大小,坐标轴标题字体大小,柱形宽度,大标题字体大小、居中)

    见链接:https://www.r-bloggers.com/how-to-make-a-histogram-with-ggplot2/ 写的很完整. 此外,关于一些参数的用法: theme(plot ...

  3. IDEA 官方背景与修改jsp模板以及字体大小

    一.官方背景切换 方法一:先打开file找到Settings  如图: 也可以用快捷方式打开:Ctrl+alt+s  打开 找到Editor点击进入 ,再然后找Color Scheme 可以看到如下图 ...

  4. AndroidStudio修改主题外观和字体大小

    修改主题外观 File --> Settings --> Appearance & Behavior --> Appearance 右边 Theme 修改编辑器的字体大小 F ...

  5. swift修改UITextfield的Placeholder字体大小和颜色

    第一种方法: self.userNumber.setValue(UIColor.lightGray, forKey: "_placeholderLabel.textColor") ...

  6. IDEA中修改各个部位的字体大小

    1.菜单栏 Setting -> Appearance&Behavior -> Appearance ->Override default fonts by (not rec ...

  7. 修改WordPress标签云字体大小颜色及标签显示数量

    WordPress 自带的标签云是一个很实用的小工具.站长可以通过标签对具有相同关健词的文章进行检索分类,利于访客查找相关文章.WordPress 默认标签云的字体最小为8pt,最大为22pt,标签显 ...

  8. VS2008中设置字体大小和添加显示行号

    1.字体设置 菜单->工具->选项->环境->字体和颜色 在字体那一栏可以选字体,VC6.0默认的字体是Fixedsys,字体大小你可以设为12,就与VC6.0的一样的字体了. ...

  9. 怎么修改windows命令行字体大小

    打开命令行窗口: 在标题栏处右键单击-->属性,然后更改即可

随机推荐

  1. 手机访问php环境移动端静态页面

    痛点 在做一个移动端H5页面,手机要调试访问,不方便.就想说能不能手机连接电脑的php项目,进行调试修改. 需要 手机要跟电脑同处在同个局域网中,公司的话一般是局域网,实在没有的话花个20块买个随身W ...

  2. Orleans-Hello World

    Orleans-Hello World http://www.rm5u.com/orleans/orleans-intro.html 什么是Orleans?          Orleans(奥尔良) ...

  3. runnable与handler结合使用,其实跟在Thread中的run()中sleep的效果是一样的

    这是一种可以创建多线程消息的函数使用方法:1,首先创建一个Handler对象Handler handler=new Handler();2,然后创建一个Runnable对象Runnable runna ...

  4. lokijs

    http://lokijs.org/#/ 500,000+ 1.1M ops/s. A fast, in-memory document-oriented datastore for node.js, ...

  5. poj 1155 TELE (树形背包dp)

    本文出自   http://blog.csdn.net/shuangde800 题目链接: poj-1155 题意 某收费有线电视网计划转播一场重要的足球比赛.他们的转播网和用户终端构成一棵树状结构, ...

  6. 立贴读 《CLR》

    弱弱的说,我要开始读<CLR>这本书了,怕自己不能坚持下来,特立贴监督自己,本来是大牛们涉及的区域,现在好朋友的鼓励下,勇敢的踏入,如有错误,还请各位指正.

  7. Windows Phone 9再见了!

    因为需要准备注册电气工程师考试,因此Windows Phone 8初学者教程的翻译只能就此打住了,在考完后,也许就是Windows Phone 9发布的时候还会回来! Bye bye!

  8. 设置HTTP代理

    Maven通过<<UserHome>>/.m2/settings.xml(如果没有该文件,复制<<MavenHome>>/conf/settings.x ...

  9. Nodejs 项目开发

    最近这几个月都在学习nodejs. 国内nodejs的资料相对较少,就我所搜索到的,CSDN目前的代码托管平台有不少从github弄过来的开源镜像,其它的不错的社区有cnodejs,byvoid的个人 ...

  10. Spark SQL 源代码分析之 In-Memory Columnar Storage 之 in-memory query

    /** Spark SQL源代码分析系列文章*/ 前面讲到了Spark SQL In-Memory Columnar Storage的存储结构是基于列存储的. 那么基于以上存储结构,我们查询cache ...