View增加红色数字角标

Java基础

浏览数:93

2020-7-16

AD:资源代下载服务

该项目提供了一种简便的方式,能够在运行期对任意给定的Android view添加徽章, 而不必配合它的布局。可添加的标签包括但不限于右上角的红色数字提醒角标



publicvoidonCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);                   finalTabHost tabHost = getTabHost();           tabHost.addTab(tabHost.newTabSpec(“demos”)                 .setIndicator(“Badge Demos”)                 .setContent(R.id.tab1));           tabHost.addTab(tabHost.newTabSpec(“adapter”)                 .setIndicator(“List Adapter”)                 .setContent(R.id.tab2));                   tabHost.addTab(tabHost.newTabSpec(“tests”)                 .setIndicator(“Layout Tests”)                 .setContent(R.id.tab3));                  // *** default badge ***                   View target = findViewById(R.id.default_target);         BadgeView badge =newBadgeView(this, target);         badge.setText(“1”);         badge.show();                   // *** set position ***                   btnPosition = (Button) findViewById(R.id.position_target);         badge1 =newBadgeView(this, btnPosition);         badge1.setText(“12”);         badge1.setBadgePosition(BadgeView.POSITION_CENTER);         btnPosition.setOnClickListener(newOnClickListener() {             @Override             publicvoidonClick(View v) {                 badge1.toggle();             }         });                   // *** badge/text size & colour ***                   btnColour = (Button) findViewById(R.id.colour_target);         badge2 =newBadgeView(this, btnColour);         badge2.setText(“New!”);         badge2.setTextColor(Color.BLUE);         badge2.setBadgeBackgroundColor(Color.YELLOW);         badge2.setTextSize(12);         btnColour.setOnClickListener(newOnClickListener() {             @Override             publicvoidonClick(View v) {                 badge2.toggle();             }         });                   // *** default animation ***                   btnAnim1 = (Button) findViewById(R.id.anim1_target);         badge3 =newBadgeView(this, btnAnim1);         badge3.setText(“84”);         btnAnim1.setOnClickListener(newOnClickListener() {             @Override             publicvoidonClick(View v) {                 badge3.toggle(true);             }         });                   // *** custom animation ***                   btnAnim2 = (Button) findViewById(R.id.anim2_target);         badge4 =newBadgeView(this, btnAnim2);         badge4.setText(“123”);         badge4.setBadgePosition(BadgeView.POSITION_TOP_LEFT);         badge4.setBadgeMargin(15,10);         badge4.setBadgeBackgroundColor(Color.parseColor(“#A4C639”));         btnAnim2.setOnClickListener(newOnClickListener() {             @Override             publicvoidonClick(View v) {                 TranslateAnimation anim =newTranslateAnimation(-100,0,0,0);                 anim.setInterpolator(newBounceInterpolator());                 anim.setDuration(1000);                 badge4.toggle(anim,null);             }         });                   // *** custom background ***                   btnCustom = (Button) findViewById(R.id.custom_target);         badge5 =newBadgeView(this, btnCustom);         badge5.setText(“37”);         badge5.setBackgroundResource(R.drawable.badge_ifaux);         badge5.setTextSize(16);         btnCustom.setOnClickListener(newOnClickListener() {             @Override             publicvoidonClick(View v) {                 badge5.toggle(true);             }         });