2014-06-11 4 views
1

이 주제는 아직 논의 된 적이 있지만 실제로하고 싶은 것을 찾지 못했습니다.외부 광선이있는 Android 버튼

버튼이 있습니다 (하단의 스크린 샷). 이제 외부 광선을 추가하고 싶습니다. drawable 폴더에 .png 파일로 저장하는 것보다이 작업을 수행 할 다른 방법이 있습니까? 그것은 훨씬 적은 노력을 할 것입니다.

인사말 닐스

the buttons now:

Like I want it

+0

** 그림자 ** (다른 ** 무언가 **), 그냥 9 패치 드로어 블을 사용하십시오. http://radleymarx.com/blog/simple-guide-to-9-patch/ –

+0

이러한 적색, 녹색 이미지가 "ImageButton"이라고 가정하면 xml의 배경을 경계에 빛나는 이미지 인 각 ImageButton에 추가 할 수 있습니다 다른 곳에서는 투명합니다. – sagarpatidar

+0

@DerGolem Illustrator에서는 이름이 이렇게 밝혀 졌다고 생각했습니다. 하지만 고마워, 나중에 너의 힌트를 시험해 보겠다. – nilskober

답변

4

이 코드

public Bitmap setGlow(int resourceId) { 
    Bitmap bmp = null; 
    try { 
     int margin = 30; 
     int halfMargin = margin/2; 

     int glowRadius = 15; 

     int glowColor = Color.rgb(0, 192, 200); 

     Bitmap src = BitmapFactory.decodeResource(getResources(), 
       resourceId); 

     Bitmap alpha = src.extractAlpha(); 

     bmp = Bitmap.createBitmap(src.getWidth() + margin, src.getHeight() 
       + margin, Bitmap.Config.ARGB_8888); 

     Canvas canvas = new Canvas(bmp); 

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

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

     canvas.drawBitmap(src, halfMargin, halfMargin, null); 

    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    return bmp; 
} 

을 시도하고 imageb에서보기에

세트를 반환 된 비트 맵을 설정 이 같은 utton

btnClick.setImageBitmap (setGlow (R.drawable.ic_launcher)));

+0

필요에 따라 광선 색상을 변경할 수 있습니다. – Meenal

+0

고맙지 만 작동하지 않습니다. 시도 : \t \t 버튼 테스트 = (버튼) findViewById (R.id.button1); \t \t Drawable d = 새 BitmapDrawable (getResources(), setGlow (R.id.buttonGruen))); \t \t test.setBackgroundDrawable (d); BitMap을 배경으로 설정했거나 ImageButton의 src로 설정 한 경우 – nilskober

+0

내게 도움이되었습니다. – Meenal