【问题标题】:custom background button missing text自定义背景按钮缺少文本
【发布时间】:2012-06-04 03:44:15
【问题描述】:

目前我正在尝试创建具有自定义背景的自定义按钮,关键是我想以编程方式为按钮创建圆角边缘。这是我创建的代码:

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());

结果是文字不见了

有什么解决办法吗?

【问题讨论】:

    标签: android button


    【解决方案1】:

    更改文本颜色

    pillButtonRight.setTextColor(Color.parseColor("#ff00ff00"));
    

    【讨论】:

    • 这个已经解决了,我注意到这是因为文本的大小和高度。
    猜你喜欢
    • 1970-01-01
    • 2022-08-16
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 2019-04-09
    • 2020-05-19
    • 1970-01-01
    相关资源
    最近更新 更多