微信消息提醒与消息数字提示之BadgeView

BadgeView 一个可以自由定制外观、支持拖拽消除的 MaterialDesign 风格 Android BadgeView。
GitHub地址:https://github.com/stefanjauker/BadgeView
代码:

MainActivity:

package com.example.jash.badgeview;

import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.DragEvent;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.jauker.widget.BadgeView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extendsAppCompatActivity {

private ViewPager pager;
    private FragmentPagerAdapter mAdapter;
    private List<Fragment> mDatas;
    private TextView FirstText;
    private TextView SecText;
    private TextView ThridText;
    private LinearLayout layout;
    private BadgeView badgeView;

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        pager =(ViewPager) findViewById(R.id.viewPager);
        initView();
        initText();
        badgeView.setOnDragListener(new View.OnDragListener() {
            @Override
            public boolean onDrag(View view, DragEvent dragEvent) {
                switch (dragEvent.getAction()) {
                }
                return false;
            }
        });
    }

private void initText() {
        FirstText = (TextView) findViewById(R.id.first);
        SecText = (TextView) findViewById(R.id.second);
        ThridText = (TextView) findViewById(R.id.thirid);
        layout =(LinearLayout) findViewById(R.id.first_layout);
    }

private void initView() {
        mDatas = new ArrayList<>();
        FirstFragment firstFragment = new FirstFragment();
        SecondFragment secondFragment = new SecondFragment();
        ThridFragment thridFragment = new ThridFragment();
        mDatas.add(firstFragment);
        mDatas.add(secondFragment);
        mDatas.add(thridFragment);
        mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()){
            @Override
            public FragmentgetItem(int position) {
                return mDatas.get(position);
            }

@Override
            public int getCount() {
                return mDatas.size();
            }
        };
        pager.setAdapter(mAdapter);
        pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

@Override
            public void onPageScrolled(int position, float positionOffset,int positionOffsetPixels) {

}

@Override
            public void onPageSelected(int position) {
                resetTextView();
                switch (position) {
                    case 0:
                        if (badgeView!= null) {
                            layout.removeView(badgeView);
                        }
                        badgeView = new BadgeView(MainActivity.this);
                        badgeView.setBadgeCount(20);
                        badgeView.setBadgeGravity(Gravity.BOTTOM | Gravity.RIGHT);
                        layout.addView(badgeView);
                        FirstText.setTextColor(Color.GREEN);
                        break;
                    case 1:
                        layout.removeView(badgeView);
                        SecText.setTextColor(Color.GREEN);
                        break;
                    case 2:
                        layout.removeView(badgeView);
                        ThridText.setTextColor(Color.GREEN);
                        break;
                }
            }

private void resetTextView() {
                FirstText.setTextColor(Color.BLACK);
                SecText.setTextColor(Color.BLACK);
                ThridText.setTextColor(Color.BLACK);
            }

@Override
            public void onPageScrollStateChanged(int state) {

}
        });
    }
}

mainXML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context="com.example.jash.badgeview.MainActivity"><include layout="@layout/top1" /><include layout="@layout/top2" /><android.support.v4.view.ViewPagerandroid:id="@+id/viewPager"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1" />
</LinearLayout>

Top1XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="50dp"android:background="#000"android:paddingLeft="12dp"android:paddingRight="12dp"><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerVertical="true"android:gravity="center"android:orientation="horizontal"><ImageViewandroid:layout_width="30dp"android:layout_height="30dp"android:src="@drawable/actionbar_icon" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="12dp"android:text="微信"android:textColor="#d3d3d3"android:textSize="18dp" /></LinearLayout><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_centerVertical="true"android:gravity="center"android:orientation="horizontal"><ImageViewandroid:layout_width="30dp"android:layout_height="30dp"android:src="@drawable/actionbar_search_icon" /><ImageViewandroid:layout_width="30dp"android:layout_height="30dp"android:src="@drawable/actionbar_add_icon" /><ImageViewandroid:layout_width="30dp"android:layout_height="30dp"android:src="@drawable/actionbar_more_icon" /></LinearLayout>
</RelativeLayout>

Top2XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="40dp"android:background="#eee"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="37dp"android:orientation="horizontal"><LinearLayoutandroid:id="@+id/first_layout"android:orientation="horizontal"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"><TextViewandroid:id="@+id/first"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="聊天"android:textColor="#0f0" /></LinearLayout><LinearLayoutandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"><TextViewandroid:id="@+id/second"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="发现"android:textColor="#000" /></LinearLayout><LinearLayoutandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:gravity="center"><TextViewandroid:id="@+id/thirid"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="通讯录"android:textColor="#000" /></LinearLayout></LinearLayout><ImageViewandroid:layout_width="match_parent"android:layout_height="3dp"android:background="@drawable/tabline" /></LinearLayout>

三个Fragment的Activity:

package com.example.jash.badgeview;import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;/*** A simple {@link Fragment} subclass.*/
public class FirstFragment extends Fragment {public FirstFragment() {// Required empty public constructor}@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {// Inflate the layout for this fragmentreturn inflater.inflate(R.layout.fragment_first, container, false);}}

Fragment的XML

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="com.example.jash.badgeview.FirstFragment"><TextViewandroid:gravity="center"android:layout_width="match_parent"android:layout_height="match_parent"android:text="聊天" /></FrameLayout>
 
 

BadgeView的主要方法:
·       setTargetView(View) 
设置控件
·       setBadgeCount(int) 
设置显示的数字
·       setBadgeGravity(Gravity) 
设置显示的位置
·       setBackgroundColor() 
设置背景色
·       setBackgroundResource() 
设置背景图片
·       setTypeface() 
设置显示字体
·       setShadowLayer() 
设置字体阴影
·       setVisibility
设置显藏状态

微信消息提醒与消息数字提示之BadgeView相关推荐

  1. 安卓实现消息提醒(震动和提示音)

    转自:http://blog.csdn.net/dyllove98/article/details/8799249 1.准备一个 音频文件 比如:beep.ogg. ogg格式是声音压缩格式的一种,类 ...

  2. 小程序的消息提醒——订阅消息

    开通订阅消息 你可在公共模板库中,选择合适的模板(或者申请新模板,申请新模板须审核后才可使用). 在小程序中融入提示用户开通订阅功能 申请发送订阅消息,需要用户手动在小程序进行触发. 将订阅消息的触发 ...

  3. android新消息提醒功能,Android仿微信新消息提示音

    怕有些人不知道怎么进入微信的新消息提示音功能,我这里说下操作步骤: 打开微信----我---设置---新消息提醒---新消息提示音. 经过以上的步骤就进入了这样的界面 具体实现的步骤. 难点之一:获取 ...

  4. 使用python+微信发送消息提醒,实现程序监控

    使用python+微信发送消息提醒,实现程序监控 使用python+微信可以非常方便的提醒自己运行的程序是否报错,监控程序运行状态 1.申请微信测试号 https://mp.weixin.qq.com ...

  5. 怎么实现一个系统的消息提醒功能

    要实现消息提醒功能,你需要考虑以下几个方面: 如何触发消息提醒:消息提醒通常是在某些特定条件触发时发出的,所以你需要定义这些触发条件.例如,可以在系统中设置触发器,在某些事件发生时触发消息提醒. 如何 ...

  6. CSS仿微信头像右上角消息数字提示

    今天写个简单的小demo,关于CSS实现头像右上角消息数字提示,样式如下如图所示,在微信和扣扣消息里面比较常见. <!DOCTYPE html> <html><head& ...

  7. android微信qq提醒功能,Android用Window实现类似微信、QQ来消息的时候的通知提示

    先上效果图 本例结合Window和动画来实现类似于微信.QQ来消息的时候的弹框提示 平时玩微信会发现,即使App在后台,但是来消息的时候仍然会弹框提示,这就肯定得用Window实现了 Window表示 ...

  8. 华为手机信息不弹屏了为什么_华为微信不弹出新消息提醒 怎么办

    介绍:说到华为,我们都知道有人问华为p9为什么不通知被锁在屏幕上的微信视频.当然也有人想问华为微信手机怎么设置密码.这是怎么回事?其实忘记华为的锁屏密码怎么办?这里提醒一下,边肖分享的华为微信不弹出新 ...

  9. Android仿QQ锁屏状态下消息提醒(震动+提示音)

    导读: 最近在开发一个定时提醒业务,类似于闹钟,然后遇到了一个问题,当APP应用在后台运行时,用户关闭了手机屏幕(手机进入灭屏休眠状态),这个时候使用系统震动和闹钟没有起到作用.why? 同样是灭屏休 ...

最新文章

  1. 学习PCL库你应该知道的C++特性
  2. postgresql中代理键
  3. hdu 4739 状压DP
  4. 剖析Jive的缓存机制
  5. DSP与STM32区别
  6. [BZOJ 1834] [ZJOI2010]network 网络扩容
  7. 摩托罗拉edge X30屏下版真机首曝:四边等宽 屏下显示效果出众
  8. Spring MVC视图解析器
  9. 随机初始化(代码实现)
  10. Hbuilder--让手爽,飞一般的编码(二)
  11. 2.1.PHP7.1 狐教程-【PHP基础】
  12. H.264 SPS/PPS成员值含义
  13. 线程Java的两种方式_[转载]Java线程的两种实现方式
  14. sql添加字段和字段说明
  15. React Native--移动端开发的救星
  16. 如何注册海外邮箱?如何进行邮箱注册163,这些技巧交给你
  17. python 方向盘_码农:科目二(可以摸方向盘了)
  18. 视频无缝续播的一些解决方案
  19. BUG记录:org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is no
  20. ubuntu mate 18.04官网下载,烧录及安装 SSH VNC ROS MAVROS librealsense realsense-ros vision_to_mavros(我自己亲自弄的)

热门文章

  1. Python--第2次平时作业
  2. P4198 楼房重建 线段树 + 区间合并
  3. Codeforces Round #712 (Div. 2) E. Travelling Salesman Problem 思维转换
  4. Triangle HDU - 5914
  5. P2486 [SDOI2011]染色
  6. 牛客网【每日一题】7月29日题目精讲—Max Power
  7. YBTOJ:采矿战略(线段树维护dp、树链剖分)
  8. CF755G-PolandBall and Many Other Balls【倍增FFT】
  9. jzoj3844-统计损失【树形dp,换根法】
  10. jzoj3913-艰难的选择【差分,统计】