android tab上显示数字(转)
16lz
2021-01-23
好多人问怎么实现tab上有数字,其实很简单实现方法有很多,这里有布局实现吧,只是demo,希望大家明白原理res/drawable/shapecount.xml
Java代码
- <?xml version="1.0" encoding="utf-8"?>
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="rectangle">
-
"20dp" /> -
"#ff2233" />
Java代码
- res/layout/tabicon.xml
- android:orientation="vertical"
- android:background="@null"
- android:id="@+id/rlayout"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" >
-
- android:id="@+id/icon"
- android:src="@android:drawable/ic_menu_mylocation"
- android:layout_margin="0dp"
- android:layout_height="wrap_content"
- android:layout_width="wrap_content"/>
-
"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" />
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);
更多相关文章
- 关于Android多项目依赖在Eclipse中无法关联源代码的问题解决 (an
- Android 7.1 触摸事件代码跟踪
- android 开发中将十六进制 颜色代码 转换为int类型数值 方法 :
- TextView --- 内容设置成上下滑动 和 代码设置字体颜色
- android微博客户端源代码
- Android 登录界面xml代码
- android 正三角,倒三角的实现代码
- Android上积累代码
- Android实用代码