2 つのボタンを重ねる必要があります。最初の (トップ) ボタンは、アイコンに .png を使用してこのように作成されます。
// 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));
2 番目のボタン (下) の場合:
Button button2 = (Button) v.findViewById(R.id.textButton);
button2.setBackgroundResource(R.drawable.gray_rect);
私が試したこと:
1 下のボタンの左側のドローアブルを上のボタンのドローアブルに設定します。結果: アイコンのみが表示され、背景色の円は表示されません。
2 ShapeDrawable を使用して RoundRectangle を作成し、次に 2 つのレイヤーを作成し、LayerDrawable を使用してボタンの背景を設定します。
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);
結果: (1) と同じ。
望ましい結果は次のとおりです。
button1 はアイコン付きの青色、button2 はテキスト付きの灰色の角丸長方形です。