0
두 개의 버튼을 레이어해야합니다. 첫 번째 (맨 위) 버튼은 아이콘에 .png를 사용하여 이와 같이 생성됩니다. 2 버튼 (아래)에 대한 프로그래밍 방식으로 설정된 그래픽/색상으로 두 개의 버튼을 레이어하는 방법
// create circular button and colorize
View button1 = v.findViewById(bId);
GradientDrawable backgroundGradient = (GradientDrawable)imgIcon.getBackground();
backgroundGradient.setColor(getResources().getColor(R.color.holo_gray_light));
// set icon
button1.setImageDrawable(getResources().getDrawable(R.drawable.ic_phone_ib));
:
나는 시도 것을
Button button2 = (Button) v.findViewById(R.id.textButton);
button2.setBackgroundResource(R.drawable.gray_rect);
:
1 위에 버튼의 그리기에 하단 버튼을 드로어 블 왼쪽을 설정합니다. 결과 : 아이콘은 배경 색이 아닌 표시됩니다.
int r= 20;
float[] outerR=new float[]{r,r,r,r,r,r,r,r};
RoundRectShape rr=new RoundRectShape(outerR,null,null);
ShapeDrawable drawable=new ShapeDrawable(rr);
drawable.getPaint().setColor(getResources().getColor(R.color.gray_189));
// get bitmap from button1
BitmapDrawable bm1 = (BitmapDrawable)button1.getDrawable();
// layer them
Drawable drawableArray[]= new Drawable[]{drawable, bm1};
LayerDrawable layerDraw = new LayerDrawable(drawableArray);
layerDraw.setLayerInset(1, 15, 15, 0, 0);//set offset of 2 layer
textButton.setBackground(layerDraw);
결과 :
2
은 쉐이프 후 2 층을 만들고 버튼의 배경 설정 LayerDrawable를 사용하여 사용 RoundRectangle을 만드는 경우와 동일하게 (1). 여기 원하는 결과이다을 button1는 아이콘 청색, 단추 2 텍스트 회색 둥근 사각형이다.