• ActionItemBadge:在actionbar上显示badge数字提示


    介绍:

    一个方便你让你在actionbar上显示数字提示的库(这种效果称为badge )。其实现原理是利用了menu菜单资源文件属性actionLayout

    运行效果:

    使用说明:

    按照正常方式创建一个menu.xml ,同事需要添加actionLayout,为了总是让这个菜单项显示出来,添加上showAsAction="always"

    <item
    android:id="@+id/item_samplebadge"
    android:actionLayout="@layout/menu_badge"
    android:showAsAction="always"
    android:title="@string/sample_1"/>

    activity中

    重写onCreateOptionsMenu

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    //you can add some logic (hide it if the count == 0)
    if(badgeCount > 0) {
    ActionItemBadge.update(this, menu.findItem(R.id.item_samplebadge), Iconify.IconValue.fa_android, ActionItemBadge.BadgeStyle.DARKGREY, badgeCount);
    } else{
    ActionItemBadge.hide(menu.findItem(R.id.item_samplebadge));
    }
    //If you want to add your ActionItem programmatically you can do this too. You do the following:
    new ActionItemBadge.Add().act(this).menu(menu).title(R.string.sample_2).itemDetails(0, SAMPLE2_ID, 1).showAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS).build(ActionItemBadge.BadgeStyle.BLUE_LARGE, 1);
    return true;
    }

    如果你想在用户点击菜单项之后重新更新badge显示的数目,那么在onOptionsItemSelected中调用invalidateOptionsMenu方法:

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if(id == R.id.item_samplebadge) {
    Toast.makeText(this, R.string.sample_3, Toast.LENGTH_SHORT).show();
    badgeCount--;
    invalidateOptionsMenu();
    return true;
    } else if(id == SAMPLE2_ID) {
    Toast.makeText(this, R.string.sample_4, Toast.LENGTH_SHORT).show();
    }
    return super.onOptionsItemSelected(item);
    }

    源码下载:http://jcodecraeer.com/a/opensource/2014/1105/1910.html

  • 相关阅读:
    在线安装eclipse中html/jsp/xml editor插件 eclipseeditor
    webstorm 破解方式
    c# 下实现ping 命令操作
    Newtonsoft 序列化和反序列化特殊处理
    jquery 页面滚动到底部自动加载插件集合
    Bootstrap 模态对话框只加载一次 remote 数据的解决办法
    CSS文本溢出处理
    js 操作table
    Js 冒泡事件阻止
    WCF4.0 –- RESTful WCF Services
  • 原文地址:https://www.cnblogs.com/noodlesonce/p/4078976.html
Copyright © 2020-2023  润新知