Note that there are some explanatory texts on larger screens.

plurals
  1. PObutton background colouring in android
    primarykey
    data
    text
    <p>i've created an android application which creates 50 button dynamically,which works perfectly, but the problem is that i can't put some background color for these buttons dynamically using code like</p> <pre><code>buttons[i][j].setTextColor(getResources().getColor(R.color.mycolor)); buttons[i][j].setBackgroundColor(getResources().getColor(R.color.mycolor)); </code></pre> <p>my code is as given below, can anyone please tell me some solution for giving background color for button</p> <pre><code>import android.app.Activity; import android.os.Bundle; import android.view.ViewGroup.LayoutParams; import android.widget.Button; import android.widget.LinearLayout; public class MyMain extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mymain); createCalender(); } public void createCalender() { LinearLayout layoutVertical = (LinearLayout) findViewById(R.id.liVLayout); LinearLayout.LayoutParams param = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f); LinearLayout rowLayout=null; Button[][] buttons = new Button[10][5]; int count=51; int tab=1; for (int i = 0; i&lt;10; i++) { if(count%5==1) { rowLayout = new LinearLayout(this); rowLayout.setWeightSum(5); layoutVertical.addView(rowLayout,param); count=count-5; } for(int j=0;j&lt;5;j++) { buttons[i][j]=new Button(this); buttons[i][j].setText(""+tab); buttons[i][j].setHeight(35); buttons[i[j].setWidth(75); buttons[i][j].setBackgroundResource(R.color.mycolor); buttons[i][j].setTextColor(Color.parseColor("#FFBBFF")); tab++; rowLayout.addView(buttons[i][j],param); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload