android的viewbadger"徽章"任何给定的Android视图,而无需在运行时布局,以迎合在一个简单的方法

1、先上图后使用;


2、使用方法

先导入android-viewbadger.jar 

然后直接在activity如下操作

View target = findViewById(控件id识别);//target为你想显示badges的控件
BadgeView badge = new BadgeView(this, target);badge.setText("1");
badge.show();//或者使用 badge .toggle();

扩展方法:setText(),

                 setTextColor(Color.BLUE),

                 setBadgeBackgroundColor(Color.YELLOW),

                 setTextSize(12),

                 toggle()等等;

3、资源下载地址:http://download.csdn.net/detail/shi508181017/5902419

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是一个简单的示例代码,用于记录个人使用轨迹和颁发不同的鼓励徽章。该代码可以用于记录用户在一个特定应用程序中的使用情况,并根据他们的使用情况颁发适当的鼓励徽章。 ``` #include <iostream> #include <fstream> #include <string> #include <map> using namespace std; // 定义枚举类型,表示不同的鼓励徽章 enum Badge { BRONZE, SILVER, GOLD }; // 定义一个结构体,表示个人使用轨迹 struct Usage { int time; int words; }; int main() { // 打开文件,读取个人使用轨迹 ifstream fin("usage.txt"); map<string, Usage> usage; string name; int time, words; while (fin >> name >> time >> words) { usage[name] = {time, words}; } fin.close(); // 统计个人使用情况,判断应该颁发哪个鼓励徽章 map<string, Badge> badges; for (auto& p : usage) { if (p.second.time >= 60 && p.second.words >= 1000) { badges[p.first] = GOLD; } else if (p.second.time >= 30 && p.second.words >= 500) { badges[p.first] = SILVER; } else if (p.second.time >= 10 && p.second.words >= 100) { badges[p.first] = BRONZE; } } // 输出个人使用轨迹和鼓励徽章 for (auto& p : usage) { cout << p.first << ": " << p.second.time << " min, " << p.second.words << " words"; if (badges.find(p.first) != badges.end()) { cout << ", Badge: "; if (badges[p.first] == BRONZE) { cout << "BRONZE"; } else if (badges[p.first] == SILVER) { cout << "SILVER"; } else if (badges[p.first] == GOLD) { cout << "GOLD"; } } cout << endl; } // 将个人使用轨迹和鼓励徽章写入文件 ofstream fout("usage.txt"); for (auto& p : usage) { fout << p.first << " " << p.second.time << " " << p.second.words; if (badges.find(p.first) != badges.end()) { if (badges[p.first] == BRONZE) { fout << " BRONZE"; } else if (badges[p.first] == SILVER) { fout << " SILVER"; } else if (badges[p.first] == GOLD) { fout << " GOLD"; } } fout << endl; } fout.close(); return 0; } ``` 该代码使用了 STL 中的 `map` 和枚举类型 `Badge`,用于存储个人使用轨迹和鼓励徽章。程序首先从文件中读取个人使用轨迹,并统计个人使用情况,根据使用情况判断应该颁发哪个鼓励徽章。然后输出个人使用轨迹和鼓励徽章,并将它们写回文件中。 注意,该代码只是一个简单的示例,实际应用中需要根据具体需求进行修改和扩展。例如,可以添加更多的使用统计指标,或者根据不同的使用情况颁发不同的鼓励徽章

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值