Android实战简易教程-第四十二枪(github实用控件推荐BadgeView-图标左上角消息提示控件)

本文介绍如何在Android应用中使用BadgeView控件,实现类似微信和QQ的左上角消息提示功能。通过步骤展示普通控件和ListView中引入消息提示的实践方法,包括控件的使用和工程导入。
摘要由CSDN通过智能技术生成

微信和QQ的左上角消息提示大家都十分有印象,有强迫症的童鞋总是忍不住的要点掉它,我们怎么将这样一个小功能引入到自己的项目中呢?

github上有一款控件可以帮助我们实现这个功能,下面我们就看一下这个控件的使用吧。

下面我们看一下自带的实例,分别介绍了普通控件和ListView控件中如何使用消息提示控件,首先我们看一下普通控件的使用。

一、普通控件引入消息提示控件:

/*
 * ViewsFragment.java
 * BadgeViewDemo
 * 
 * Copyright (c) 2013 Stefan Jauker.
 * https://github.com/kodex83/BadgeView
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.jauker.badgeview.example;

import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.jauker.widget.BadgeView;


public class ViewsFragment extends Fragment implements OnClickListener {

    private BadgeView backgroundDrawableBadge;
    private BadgeView backgroundShapeBadge;
    private BadgeView backgroundDefaultBadge;
    private BadgeView counterBadge;
    private BadgeView gravityBadge;
    private BadgeView textStyleBadge;
    private BadgeView visibilityBadgeView;

    /*
     * (non-Javadoc)
     * 
     * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
     */
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View layout = inflater.inflate(R.layout.fragment_views, null);

        View backgroundDefaultView = layout.findViewById(R.id.backgroundDefault);
        backgroundDefaultBadge = new BadgeView(getActivity());//初始化控件
        backgroundDefaultBadge.setBadgeCount(42);
        backgroundDefaultBadge.setTargetView(backgroundDefaultView);

        View backgroundDrawableView = layout.findViewById(R.id.backgroundDrawable);
        backgroundDrawableBadge = new BadgeView(getActivity());
       
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值