仿照qq紅色消息數目提示ViewBadger

1,確定是先引包android_viewBadger.jarjava

2,而後就是用法了android

   首先定義變量  BadgeView badger ;ide

//函數

  oncreate()方法中使用該變量this

  badger = new BadgeView(ltmain.this,lin_z);
  badger.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);//POSITION_TOP_RIGHT
  badger.setGravity(Gravity.CENTER);//設置居中code

//SetbadgetView();//寫一個函數獲取打點的數目
public void SetbadgetView()
 {
  new Thread(){
   public void run() {
    String result = lt.GetspltAllzxjczbcount(user_bh, user_paw, ssqbh);
    try {
     if (!TextUtils.isEmpty(result)) {
      number = result ;
     }else {
      number = "0" ; 
     }
    } catch (Exception e) {
     // TODO: handle exception
     number = "" ;
    }
    try {
     count = Integer.parseInt(result);
     runOnUiThread(new Runnable() {
      public void run() {
       SetBadgerView(0);
       if (count > 0) {
        badger.show();
       }else {
        badger.hide();
       }
      }
     });
    } catch (Exception e) {
     // TODO: handle exception
    }
   };
  }.start();
 }
 public void SetBadgerView(int index){
  if (count > 1) {
   count = count - index ;
  }else {
   badger.hide();
  }
  badger.setText(String.valueOf(count));
 }
相關文章
相關標籤/搜索