Android 自定义ActionBar.Tab对象的表现



最近想修改ActionBar.Tab对象的文本字体和颜色

发现该对象提供的接口非常有限

而网上搜索关于ActionBar.Tab结果大多比较早 使用的也不是google提供的例子中的ActionBar

于是自己研究了一天 找到了使用接口setCustomView来自定义ActionBar.Tab对象


先通过ActionBar.getTabAt(int) 获得一个ActionBar.Tab对象

然后调用setCustomView 使用自定义的layout

注意这里没有生产layout的对象 而是直接使用该布局

布局可以定制好设置文本大小 背景 颜色

后面就和使用普通布局一样 

获得一个TextView 再设置文本 背景 等等


actionBar = getSupportActionBar();

ActionBar.Tab t = actionBar.getTabAt(i);
t.setCustomView(R.layout.tab_layout_1);
TextView title = (TextView)t.getCustomView().findViewById(R.id.tab_title);
title.setBackgroundResource(R.drawable.detail);
title.setText(sectionID);

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    
	<TextView
	    android:id="@+id/tab_title"
	    android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	    android:layout_marginTop="5dp"
	    android:layout_gravity="center_vertical|center"
	    android:textColor="@android:color/holo_blue_dark"
	    android:textSize="14sp" />

</FrameLayout>


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值