android tab上显示数字
16lz
2021-12-04
好多人问怎么实现tab上有数字,其实很简单实现方法有很多,这里有布局实现吧,只是demo,希望大家明白原理res/drawable/shapecount.xml
Java代码- <?xmlversion="1.0"encoding="utf-8"?>
- <shape
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="rectangle">
- <cornersandroid:radius="20dp"/>
- <solidandroid: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"<!--Justfortest-->
- android:layout_margin="0dp"
- android:layout_height="wrap_content"
- android:layout_width="wrap_content"/>
- <TextViewandroid: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.txtCount);spec = tabHost.newTabSpec("artists").setIndicator(view).setContent(intent);
更多相关文章
- 浅谈Java中Collections.sort对List排序的两种方法
- python list.sort()根据多个关键字排序的方法实现
- Android(安卓)Kotlin开发模块之间跳转-ARouter
- Android(安卓)在非UI线程直接更新UI信息
- Android百度地图一种简单实现多标注及响应时间的方法
- 圆形button
- Xposed: 勾住(Hook) Android应用程序对象的方法,实现AOP
- [Android] 利用Handler实现定时器功能
- android如何改变默认横竖屏方向