导航栏图标上添加 提醒
来源:互联网 发布:软件体验报告 编辑:程序博客网 时间:2024/04/26 15:57
private ImageView iv;
private ImageView iv2;
private ImageView iv3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.iv);
iv2 = (ImageView) findViewById(R.id.iv2);
iv3 = (ImageView) findViewById(R.id.iv3);
Bitmap b1 = getResIcon(getResources(), R.drawable.app_logo);
Bitmap b2 = generatorContactCountIcon(b1,5);
iv.setBackgroundDrawable(new BitmapDrawable(b2));
BadgeView badgeView = new BadgeView(MainActivity.this, iv2);
badgeView.setText("27");
badgeView.setTextSize(20.5f);
badgeView.setTextColor(Color.DKGRAY);
badgeView.show();
BadgeView badgeView2 = new BadgeView(MainActivity.this, iv3);
badgeView2.setBackgroundResource(R.drawable.noread);
badgeView2.show();
}
/**
* 鑾峰彇Icon瀵瑰簲鐨刡itmap
* @param res
* @param resId
* @return
*/
private Bitmap getResIcon(Resources res, int resId) {
Drawable icon = res.getDrawable(resId);
if (icon instanceof BitmapDrawable) {
BitmapDrawable bd = (BitmapDrawable) icon;
return bd.getBitmap();
} else {
return null;
}
}
/**
* 鍦ㄧ粰瀹氱殑鍥剧墖鐨勫彸涓婅鍔犱笂绾㈣壊鎻愰啋鏁伴噺
*
* @param icon
* 缁欏畾鐨勫浘鐗�
* @return 甯﹁仈绯讳汉鏁伴噺鐨勫浘鐗�
*/
private Bitmap generatorContactCountIcon(Bitmap icon,int count) {
// 鍒濆鍖栫敾甯�
int iconSize = (int) getResources().getDimension(
android.R.dimen.app_icon_size);
Bitmap contactIcon = Bitmap.createBitmap(iconSize, iconSize,
Config.ARGB_8888);
Canvas canvas = new Canvas(contactIcon);
// 鎷疯礉鍥剧墖
Paint iconPaint = new Paint();
iconPaint.setDither(true);// 闃叉姈鍔�
iconPaint.setFilterBitmap(true);// 鐢ㄦ潵瀵笲itmap杩涜婊ゆ尝澶勭悊锛岃繖鏍凤紝褰撲綘閫夋嫨Drawable鏃讹紝浼氭湁鎶楅敮榻跨殑鏁堟灉
Rect src = new Rect(0, 0, icon.getWidth(), icon.getHeight());
Rect dst = new Rect(0, 0, iconSize, iconSize);
canvas.drawBitmap(icon, src, dst, iconPaint);
// 鍚敤鎶楅敮榻垮拰浣跨敤璁惧鐨勬枃鏈瓧璺�
Paint countPaint = new Paint(Paint.ANTI_ALIAS_FLAG
| Paint.DEV_KERN_TEXT_FLAG);
countPaint.setColor(Color.RED);
countPaint.setTextSize(20f);
countPaint.setTypeface(Typeface.DEFAULT_BOLD);
canvas.drawText(String.valueOf(count), iconSize - 18, 25, countPaint);
return contactIcon;
}
}
xml 文件
<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" >
<ImageView
android:id="@+id/iv"
android:layout_width="80dp"
android:layout_height="100dp"
android:scaleType="fitXY" />
<ImageView
android:id="@+id/iv2"
android:layout_width="80dp"
android:layout_height="100dp"
android:layout_marginTop="30dp"
android:scaleType="fitXY"
android:src="@drawable/app_logo" />
<ImageView
android:layout_marginTop="30dp"
android:id="@+id/iv3"
android:layout_width="80dp"
android:layout_height="100dp"
android:scaleType="fitXY"
android:src="@drawable/app_logo" />
</LinearLayout>
- 导航栏图标上添加 提醒
- Android 图标上面添加提醒
- Android 图标上面添加提醒
- 添加导航栏右侧 rss 图标
- 使用BottomNavigationView底部导航栏、添加数量角标提醒
- Android 图标右上角添加数字提醒
- 在UIView上添加一个导航栏
- 在导航栏上添加控件
- 在导航栏上添加按钮
- 怎么在android4.4上添加未读信息,未接来电或日历等新事件图标提醒
- 导航栏图标问题
- Android 图标上面添加提醒(一)使用Canvas绘制
- Android 图标上面添加提醒(一)使用Canvas绘制
- Android 图标上面添加提醒(一)使用Canvas绘制
- Android 图标上面添加提醒(一)使用Canvas绘制
- [android]在图标上加提醒的数字
- 在导航栏上添加搜索框的问题
- 自定义底部导航栏图标
- SVN中的branch和tag
- C++ 学习笔记_0022_指针(指来指去、阅读程序)
- 文件编程(3)文件锁
- Building an MFC project for a non-Unicode character set is deprecated
- Docker 搭建wordpress 环境 -- 前后端分离
- 导航栏图标上添加 提醒
- java验证码识别--1
- Photoshop使用边缘功能打造后期画意
- Django集成Ueditor富文本编辑器及少量功能定制详解
- POJ-2553-The Bottom of a Graph 解题报告
- Java基础----Calendar
- 如何做好扁平化设计:交互篇(2)
- 安装win7系统时,硬盘模式为IDE模式时安装成功,硬盘模式为AHCI模式时重启蓝屏或一直启动的问题,以及IDE模式与AHCI模式的区别!
- 怎么实现高收益