• Android 图标右上角添加数字提醒


    方法一:使用开源项目ViewBadger,github上的地址:https://github.com/jgilfelt/android-viewbadger

    效果如图所示:

    1. <TextView  
    2.        android:id="@+id/tv1"  
    3.        android:layout_width="wrap_content"  
    4.        android:layout_height="wrap_content"  
    5.        android:padding="15dp"  
    6.        android:text="文本1" />  
    1. <span style="font-family: Arial, Helvetica, sans-serif;"></span>  
    1. tv = (TextView) findViewById(R.id.tv1);  
    2. BadgeView badgeView = new BadgeView(MainActivity.this, tv);  //实例化BadgeView  
    3.          badgeView.setText("12");  
    4. //       badgeView.setTextSize(8.5f);  //设置文字的大小  
    5.          badgeView.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);//设置在右上角  
    6.          badgeView.setTextColor(Color.DKGRAY);  //字体的设置颜色  
    7.          badgeView.show(); //显示  

    1.   
    这样就实现了上面的效果,注意引用开源项目ViewBadger时,要和新建的工程文件在同一个文件夹内,否则会出错的
     

    方法二:用框架架构布局FrameLayout

    效果如图所示:
    布局如下:这样就可以了
    1. <FrameLayout  
    2.         android:id="@+id/frameLayout1"  
    3.         android:layout_width="wrap_content"  
    4.         android:layout_height="wrap_content" >  
    5.   
    6.         <TextView  
    7.             android:id="@+id/textView1"  
    8.             android:layout_width="wrap_content"  
    9.             android:layout_height="wrap_content"  
    10.             android:padding="10dp"  
    11.             android:text="文本2" />  
    12.   
    13.         <TextView  
    14.             android:layout_width="wrap_content"  
    15.             android:layout_height="wrap_content"  
    16.             android:layout_gravity="top|right"  
    17.             android:background="#FF0000"  
    18.             android:text="23"  
    19.             android:textColor="@android:color/white" />  
    20.   
    21.         </FrameLayout>  

  • 相关阅读:
    MySQL数据库初识
    Python中面向对象初识到进阶
    python 函数进阶
    Python 函数的初识
    Python的发展与应用
    什么是产品经理 以及职责
    I/O----复制文本文件
    获取次日日期(主要两种方法)
    vector以及array和数组
    编辑软件注释快捷键
  • 原文地址:https://www.cnblogs.com/Free-Thinker/p/3738023.html
Copyright © 2020-2023  润新知