当前位置: 代码迷 >> Android >> android tab上展示数字(转)
  详细解决方案

android tab上展示数字(转)

热度:7   发布时间:2016-05-01 20:41:58.0
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);
?






  相关解决方案