目前我正在尝试使用自定义背景创建自定义按钮,重点是我想以编程方式为按钮创建圆角边缘。这是我创建的代码:
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);
getcreenwidth和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());
结果是文字消失了
有没有解决这个问题?
答案 0 :(得分:0)
更改文字颜色
pillButtonRight.setTextColor(Color.parseColor("#ff00ff00"));