开源组件viewbadger实现消息数字提示,项目地址:https://github.com/jgilfelt/android-viewbadger (可获得源码)!
Author: Jeff Gilfelt
The code in this project is licensed under the Apache Software License 2.0.
Copyright (c) 2011 readyState Software Ltd.
当然,这里直接是一个jar包,导入就可使用:android-viewbadger.jar(Demo中有jar包)
实例Demo:
MainActivity.java:
package sn.qdj.viewbadgerdemo; import com.readystatesoftware.viewbadger.BadgeView; import android.app.Activity; import android.os.Bundle; import android.view.View; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); View btn = findViewById(R.id.button1); BadgeView badge = new BadgeView(this, btn); badge.setTextSize(12); /** * 右上角(默认值) */ badge.setBadgePosition(BadgeView.POSITION_TOP_RIGHT); badge.setText("10"); badge.show(); } }
显示效果:
时间: 2024-10-11 19:27:04