Java code
Many people have asked how to implement a number on the tab. Actually, there are many simple implementation methods. There are layout implementation here, just a demo. I hope you can understand the principles of res/drawable/shapecount. xml.
<? Xml version = "1.0" encoding = "UTF-8"?>
<Shape
Xmlns: android = "http://schemas.android.com/apk/res/android"
Android: shape = "rectangle">
<Corners android: radius = "20dp"/>
<Solid android: color = "# ff2233"/>
</Shape>
Res/layout/tabicon. xml
<RelativeLayout
Android: orientation = "vertical"
Android: background = "@ null"
Android: id = "@ + id/rlayout"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content">
<ImageView
Android: id = "@ + id/icon"
Android: src = "@ android: drawable/ic_menu_mylocation" <! -- Just for test -->
Android: layout_margin = "0dp"
Android: layout_height = "wrap_content"
Android: layout_width = "wrap_content"/>
<TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content"
Android: text = "50" android: textSize = "12dp" android: textStyle = "bold"
Android: background = "@ drawable/shapecount"
Android: textColor = "# FFFFFF"
Android: paddingLeft = "3dp" android: paddingRight = "3dp"
Android: layout_margin = "0dp"
Android: layout_alignBottom = "@ + id/rlayout"
Android: id = "@ + id/txtCount"/>
</RelativeLayout>
LayoutInflater inflater = LayoutInflater. from (this );
View view = inflater. inflate (R. layout. tabicon, null );
Final TextView txtCount = (TextView) view.findViewById(R.id.txt Count );
Spec = tabHost. newTabSpec ("artists"). setIndicator (view). setContent (intent );