微信和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());