-1

プログラムで と を追加Text ViewしましButtonた。

コード

final TextView test = new TextView(getApplicationContext());
test.setText(String.valueOf(counterQuantity));
test.setTextColor(getResources().getColor(R.color.black));
test.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);

GradientDrawable border = new GradientDrawable();
border.setShape(GradientDrawable.OVAL);
border.setStroke(1, getResources().getColor(R.color.black));
border.setCornerRadius(2);
border.setColor(getResources().getColor(R.color.colorPrimaryDark)); //white background
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
  test.setBackgroundDrawable(border);
} else {
  test.setBackground(border);
}

Button articleButtonId = (Button) v;
int articleButton = articleButtonId.getId();
final String articleButtonText = articleButtonId.getText().toString();
Log.w("articleButton", "" + articleButton);

final Button button = new Button(getApplicationContext());
button.setText(test.getText() + "  " + "  " + articleButtonText);
button.setGravity(Gravity.CENTER);
button.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
button.setTextColor(getResources().getColor(R.color.black));
button.setBackgroundColor(getResources().getColor(R.color.article_button_group));
button.setBackground(getResources().getDrawable(R.drawable.order_button_group_bg));

上記のコードでは、プログラムでText Viewと を追加しています。Button

Text Views連結を使用して追加された内部Button setTextメソッドのテキスト。

Text View今、私はでだけ作りたいCircle View.

で試してみましGradientDrawableたが、 の効果Text Viewは同じままで、 が受ける効果はありませんText View

他のシナリオGradientDrawableでは正常に動作していますが、このシナリオでは必要なものが得られません。

これがまさに私が欲しいイメージです。

ここに画像の説明を入力

どんな助けでも大歓迎です。

4

1 に答える 1