android tablehost中tab中显示数字
16lz
2021-01-23
转载:http://wang-peng1.iteye.com/blog/1177747
[img]
好多人问怎么实现tab上有数字,其实很简单实现方法有很多,这里有布局实现吧,只是demo,希望大家明白原理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.txtCount);spec = tabHost.newTabSpec("artists").setIndicator(view).setContent(intent);
[img]
更多相关文章
- Android百分比布局(PercentRelativeLayout)嵌套NavigationView自
- Android中自定义控件之飞入飞出布局及随机布局实现方式
- adroid 现行布局水平居中位置
- Android百分比布局
- 完美解决Android Studio在写XML布局的时候没有了控件代码提示的
- Android 子控件高度超出父布局的限制
- android开发 使用uses-sdk 导致布局不一样解决
- android studio无法在可视化页面预览布局文件