Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android TableLayout中按钮的背景色_Android - Fatal编程技术网

Android TableLayout中按钮的背景色

Android TableLayout中按钮的背景色,android,Android,我很难弄清楚为什么会这样: TableLayout table = (TableLayout) this.findViewById(R.id.tablelayout); int counter = 1; for (int i = 0; i < nrows; i++) { TableRow row = new TableRow(this); table.addView(row); for (int j = 0; j &l

我很难弄清楚为什么会这样:

    TableLayout table = (TableLayout) this.findViewById(R.id.tablelayout);
    int counter = 1;
    for (int i = 0; i < nrows; i++) {
        TableRow row = new TableRow(this);
        table.addView(row);
        for (int j = 0; j < ncols; j++) {
            FrameLayout cell = new FrameLayout(this);
            cell.setBackgroundColor((i + j) % 2 == 0 ? Color.YELLOW : Color.WHITE);
            Button b = new Button(this, null, android.R.attr.buttonStyleSmall);
            b.setTextSize(TypedValue.COMPLEX_UNIT_DIP,10);
            b.setText("B-\n" + Integer.toString(counter++));
            b.setPadding(0,0,0,0);
            b.setLayoutParams(new FrameLayout.LayoutParams(120, 120, 0x11));
                // 0x11 = center
            if (i == 3 && j == 3)
                b.setBackground(new ColorDrawable(0xcc0088));
            cell.addView(b);
            row.addView(cell);
            cell.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.MATCH_PARENT, 1F));
        }
        row.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1F));
    }
TableLayout table=(TableLayout)this.findviewbyd(R.id.TableLayout);
int计数器=1;
对于(int i=0;i
我使用的是
nrows==10
ncols==5
。这将显示一个由白色和黄色“方块”组成的棋盘格图案,除(3,3)之外的每个方块的中心是一个灰色按钮,其中包含一些文本。不过,在(3,3)正方形中,我使用了带有一种洋红色的
彩色可绘制的
设置背景,只有文本出现;除文字外,正方形全是黄色。没有灰色按钮,但我尝试应用于按钮的洋红色也没有显示在任何地方。(使用
b.setBackgroundColor(0xcc0088)
具有相同的结果。)


对发生的事情有什么解释吗?我是否遗漏了一些明显的东西,或者
表格布局中的按钮是否有不同的行为,或者是什么?如何以编程方式设置按钮的颜色,而不更改封闭正方形的颜色?

(0xcc0088)的alpha为0,这是您想要的吗?我不认为so@pskink呜呜呜呜呜呜。。。谢谢我希望这是件简单的事。