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

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

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






更多相关文章

  1. 浅谈Java中Collections.sort对List排序的两种方法
  2. python list.sort()根据多个关键字排序的方法实现
  3. Android(安卓)Kotlin开发模块之间跳转-ARouter
  4. Android(安卓)在非UI线程直接更新UI信息
  5. Android百度地图一种简单实现多标注及响应时间的方法
  6. 圆形button
  7. Xposed: 勾住(Hook) Android应用程序对象的方法,实现AOP
  8. [Android] 利用Handler实现定时器功能
  9. android如何改变默认横竖屏方向

随机推荐

  1. Android(安卓)- TextView限制文本长度,英
  2. Android支持的资源
  3. android主要有5中数据存储方式
  4. Android(安卓)Spinner,下拉菜单的功能和用
  5. Android开发指南1-框架主题-基础知识
  6. Android应用程序通过JNI控制LED
  7. android 单选按钮组的使用
  8. 性能优化之Java(Android)代码优化
  9. android资源管理和使用资源 (2015.12.1)
  10. Android(安卓)SDK Installed On Mac