方法一:使用开源项目ViewBadger,github上的地址:https://github.com/jgilfelt/android-viewbadger
效果如图所示:
- <TextView
- android:id="@+id/tv1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:padding="15dp"
- android:text="文本1" />
- <span style="font-family: Arial, Helvetica, sans-serif;"></span>
- tv = (TextView) findViewById(R.id.tv1);
- BadgeView badgeView = new BadgeView(MainActivity.this, tv);
- badgeView.setText("12");
-
- badgeView.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
- badgeView.setTextColor(Color.DKGRAY);
- badgeView.show();
这样就实现了上面的效果,注意引用
开源项目ViewBadger时,要和新建的工程文件在同一个文件夹内,否则会出错的
方法二:用框架架构布局FrameLayout
效果如图所示:
布局如下:这样就可以了
- <FrameLayout
- android:id="@+id/frameLayout1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" >
-
- <TextView
- android:id="@+id/textView1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:padding="10dp"
- android:text="文本2" />
-
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="top|right"
- android:background="#FF0000"
- android:text="23"
- android:textColor="@android:color/white" />
-
- </FrameLayout>
Android 图标右上角添加数字提醒,布布扣,bubuko.com
Android 图标右上角添加数字提醒
原文:http://www.cnblogs.com/Free-Thinker/p/3738023.html