android tab上显示数字(转)

好多人问怎么实现tab上有数字,其实很简单实现方法有很多,这里有布局实现吧,只是demo,希望大家明白原理res/drawable/shapecount.xml

 

Java代码   收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <shape  
  3.     xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     android:shape="rectangle">  
  5.   <corners android:radius="20dp"  />      
  6.   <solid android:color="#ff2233" />  
  7. </shape>  

 

 

Java代码   收藏代码
  1. res/layout/tabicon.xml  
  2.   
  3. <RelativeLayout  
  4.     android:orientation="vertical"  
  5.     android:background="@null"  
  6.     android:id="@+id/rlayout"  
  7.     android:layout_width="wrap_content"  
  8.     android:layout_height="wrap_content" >  
  9.     <ImageView   
  10.             android:id="@+id/icon"  
  11.             android:src="@android:drawable/ic_menu_mylocation" <!-- Just for test -->  
  12.             android:layout_margin="0dp"  
  13.             android:layout_height="wrap_content"   
  14.             android:layout_width="wrap_content"/>  
  15.   
  16.     <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"  
  17.         android:text="50" android:textSize="12dp" android:textStyle="bold"    
  18.         android:background="@drawable/shapecount"  
  19.         android:textColor="#FFFFFF"  
  20.         android:paddingLeft="3dp" android:paddingRight="3dp"  
  21.             android:layout_margin="0dp"  
  22.         android:layout_alignBottom="@+id/rlayout"  
  23.         android:id="@+id/txtCount" />  
  24.   
  25. </RelativeLayout>  


     LayoutInflater inflater = LayoutInflater.from(this);
 View view = inflater.inflate(R.layout.tabicon, null);
final TextView txtCount = (TextView) view.findViewById(R.id.txtCount);

spec = tabHost.newTabSpec("artists").setIndicator(view).setContent(intent);
 






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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值