2012-08-28 53 views
6

如何在圖標上獲得藍色發光效果?有沒有快速的方法來做到這一點?我真的不想用這個效果的Photoshop。Android - 如何使圖標發光觸摸?

任何幫助將非常感激。

+0

你必須要使用statelistdrawables中,您將定義藍色effect.Please訪問線程http://stackoverflow.com/questions/6501716/android-how-to-create-a-statelistdrawable-programmatically 或者您可以訪問http://developer.android.com/guide/topics/resources/ drawable-resource.html –

回答

21

如果您希望通過編程產生輝光,這裏是你如何能做到。我的建議是,在你的活動beggining產生它只是一次,然後用它創建一個StateListDrawable,如評論說:

// An added margin to the initial image 
    int margin = 24; 
    int halfMargin = margin/2; 

    // the glow radius 
    int glowRadius = 16; 

    // the glow color 
    int glowColor = Color.rgb(0, 192, 255); 

    // The original image to use 
    Bitmap src = BitmapFactory.decodeResource(getResources(), 
      R.drawable.ic_launcher); 

    // extract the alpha from the source image 
    Bitmap alpha = src.extractAlpha(); 

    // The output bitmap (with the icon + glow) 
    Bitmap bmp = Bitmap.createBitmap(src.getWidth() + margin, 
      src.getHeight() + margin, Bitmap.Config.ARGB_8888); 

    // The canvas to paint on the image 
    Canvas canvas = new Canvas(bmp); 

    Paint paint = new Paint(); 
    paint.setColor(glowColor); 

    // outer glow 
    paint.setMaskFilter(new BlurMaskFilter(glowRadius, Blur.OUTER)); 
    canvas.drawBitmap(alpha, halfMargin, halfMargin, paint); 

    // original icon 
    canvas.drawBitmap(src, halfMargin, halfMargin, null); 

    ((ImageView) findViewById(R.id.bmpImg)).setImageBitmap(bmp); 
+0

我真的很喜歡你用註釋來解釋這些東西的方式。謝謝。 – Varundroid