Android桌面应用快捷程序的开发

快捷图标有两部分组成,一部分是应用的图标,另一部分就是应用的名称。其实Launcher中的快捷图标只是继承了TextView控件,重绘了一下,将背景弄成浅灰色(具体是什么颜色我也不知道)的椭圆背景,显示的文字颜色则是白色。TextView有android:drawableTop等属性,用来显示应用的图标。

Android桌面应用快捷程序的开发
创建BuddleTextView类:

package com.lyc;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.text.Layout;
import android.util.AttributeSet;
import android.widget.TextView;

public class BuddleTextView extends TextView{
 private static final int CORNER_RADIUS = 8; 
    private static final int PADDING_H = 5; 
    private static final int PADDING_V = 1; 
    private final RectF mRect = new RectF(); 
    private Paint mPaint; 
    public  BuddleTextView(Context context) { 
        super(context); 
        init(); 
}
    public BuddleTextView(Context context, AttributeSet attrs) { 
        super(context, attrs); 
        init(); 
   
    public BuddleTextView(Context context, AttributeSet attrs, int defStyle) { 
        super(context, attrs, defStyle); 
        init(); 
    }
 private void init() {
  // TODO Auto-generated method stub
  setFocusable(true); 
        // We need extra padding below to prevent the bubble being cut. 
        setPadding(PADDING_H, 0, PADDING_H, PADDING_V); 
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 
        mPaint.setColor(getContext().getResources() 
                .getColor(R.color.bubble_dark_background)); 
 }
  protected void drawableStateChanged() { 
         invalidate(); 
         super.drawableStateChanged(); 
    
     @Override 
     public void draw(Canvas canvas) { 
         final Layout layout = getLayout(); 
         final RectF rect = mRect; 
         final int left = getCompoundPaddingLeft(); 
         final int top = getExtendedPaddingTop(); 
         rect.set(left + layout.getLineLeft(0) - PADDING_H, 
                  top + layout.getLineTop(0) - PADDING_V, 
                  Math.min(left + layout.getLineRight(0) + PADDING_H, 
                           getScrollX() + getRight() - getLeft()), 
                  top + layout.getLineBottom(0) + PADDING_V); 
         canvas.drawRoundRect(rect, CORNER_RADIUS, CORNER_RADIUS, mPaint); 
         super.draw(canvas); 
    
}
配置文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.lyc"
      android:versionCode="1"
      android:versionName="1.0">


    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".ApplicationDemo"
            android:theme="@android:style/Theme.Translucent"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".BuddleTextView"/>

    </application>
</manifest>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值