launcher3图标icon背景及文字处理

本文详细介绍了Android系统中Launcher3应用图标背景的绘制过程及所涉及的关键代码片段。包括图标聚焦背景、图标文字背景的资源文件位置,以及如何通过代码实现不同状态下的图标背景效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

   图标聚焦背景

packages\apps\Launcher3\res\drawable\focusable_view_bg.xml


   图标文字背景

packages\apps\Launcher3\src\com\android\launcher3\BubbleTextView.java



packages\apps\Launcher3\src\com\android\launcher3\Utilities.java


    static final int[] APP_ICON_BG = {  
        R.drawable.appsiconbg,  
        R.drawable.appsiconbg,  
        R.drawable.appsiconbg,  
        R.drawable.appsiconbg,  
        R.drawable.appsiconbg  
    };

 static Bitmap createIconBitmap(Drawable icon, Context context) {

        synchronized (sCanvas) { 

...

            if (debug) {
                // draw a big box for the icon for debugging
                canvas.drawColor(sColors[sColorIndex]);
                if (++sColorIndex >= sColors.length) sColorIndex = 0;
                Paint debugPaint = new Paint();
                debugPaint.setColor(0xffcccc00);
                canvas.drawRect(left, top, left+width, top+height, debugPaint);
            }


            
            if (true) 
            {
                int index = new Random(System.currentTimeMillis()).nextInt(5);

//Bitmap backBitmap = BitmapFactory.decodeResource(context.getResources(),APP_ICON_BG[index]);
                Bitmap backBitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.appsiconbg);
                int backWidth = backBitmap.getWidth();
                int backHeight = backBitmap.getHeight();
                if(backWidth != sIconWidth || backHeight != sIconHeight)
                {
                    Matrix matrix = new Matrix();
                    matrix.postScale((float)sIconWidth/backWidth, (float)sIconHeight/backHeight);
                    canvas.drawBitmap(Bitmap.createBitmap(backBitmap, 0, 0, backWidth, backHeight, matrix, true),0.0f, 0.0f, null);
                }else
                {
                    canvas.drawBitmap(backBitmap, 0.0f, 0.0f, null);
                }
            }     

...

// 如果原图标太大,看不到背景,可以把原图标缩小

            //icon.setBounds(left, top, left+width, top+height);
            icon.setBounds(left+15, top+15, left+width-15, top+height-15);

}

参考http://blog.csdn.net/xuhui_7810/article/details/36901815


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值