【问题标题】:Android button setBackground colour without size changingAndroid按钮设置背景颜色不改变大小
【发布时间】:2016-02-21 06:35:56
【问题描述】:

我通过代码将 7x7 按钮集添加到表格 TableLayout 中,在我想为按钮设置背景颜色之前一切都很好。 enter image description here

在我设置背景颜色后,按钮变得比以前大了..

这是我的代码

private void initGameBoard(){

    mTableLayout= (TableLayout) findViewById(R.id.table_layout);

    int counter = 1;
    for(int row=0;row<7;row++) {
        TableRow tableRow=new TableRow(this);
        for(int col=0;col<7;col++) {

            mTableLayout.setColumnShrinkable(col, true);

            Button button=new Button(this);

            button.setTag(counter);

            if (counter == 2){

                button.setBackgroundColor(Color.YELLOW);
            }

            tableRow.addView(button);

            counter++;

        }

        mTableLayout.addView(tableRow, new LayoutParams(FP, WC));
    }


}

【问题讨论】:

    标签: android android-tablelayout


    【解决方案1】:

    要设置按钮背景颜色,试试这个..

    button.getBackground().setColorFilter(Color.YELLOW, PorterDuff.Mode.MULTIPLY);

    【讨论】:

      猜你喜欢
      • 2015-09-09
      • 1970-01-01
      • 2015-10-29
      • 1970-01-01
      • 1970-01-01
      • 2020-03-10
      • 2015-10-25
      • 1970-01-01
      相关资源
      最近更新 更多