目前我正在尝试创建具有自定义背景的自定义按钮,关键是我想以编程方式为按钮创建圆角边缘。这是我创建的代码:
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());
结果文字不见了
有什么解决办法吗?