1

現在、カスタム背景でカスタム ボタンを作成しようとしています。ポイントは、プログラムでボタンの丸みを帯びたエッジを作成することです。これは私が作成するコードです:

GradientDrawable gd = new GradientDrawable(Orientation.TOP_BOTTOM, new int[] {Color.parseColor("#ffffff"),Color.parseColor("#999999")});
gd.setCornerRadii(new float[] { 0, 0, 10, 10, 10, 10, 0, 0 });
gd.setStroke(1, Color.parseColor("#33364252"));

Button pillButtonRight = new Button(this);
pillButtonRight.setId(R.id.pillButtonRight);
pillButtonRight.setBackgroundDrawable(gd);  
pillButtonRight.setWidth(ViewUtils.getScreenWidth(getBaseContext())/8);
pillButtonRight.setHeight(ViewUtils.getScreenHeight(getBaseContext())/40);
pillButtonRight.setText("English");     
pillButtonRight.setTextColor(Color.parseColor("#000000"));
pillButtonRight.setTextSize(12);

getscreenwidth と getscreenheight の背後にあるコードは次のとおりです。

WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int screenWidthDp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, display.getWidth(), ctx.getResources().getDisplayMetrics());

その結果、テキストがなくなりました

これに関する回避策はありますか?

4

1 に答える 1

0

テキストの色を変更する

pillButtonRight.setTextColor(Color.parseColor("#ff00ff00"));
于 2012-06-04T04:48:03.443 に答える