2016-02-21 62 views
0

我添加了7x7按钮设置为表TableLayout的代码,一切都很好,我想为背景色设置一个按钮。 enter image description hereAndroid按钮setBackground颜色没有大小变化

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

这里是我的代码

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


} 

回答

0

对于设置按钮的背景颜色,试试这个..

按钮。 getBackground()。setColorFilter(Color.YELLOW,PorterDuff.Mode.MULTIPLY);