I want to change background color of particular textview
. Need different background for each textview
. I write this code, textview
make but this give error
"textview.findViewById().setBackgroundColor(Color.RED);"
Textview textview;
for (int i = 0; i < 3; i++) {
textview = new TextView(this);
textview .setId(i);
textview .setTextSize(15);
textview .setTextColor(Color.BLACK);
}
textview.findViewById(1).setBackgroundColor(Color.RED);
self Solution
Use Linear layout and add textview
then change
LinearLayout linear_layout;
Textview textview;
for (int i = 0; i < 3; i++) {
textview = new TextView(this);
textview .setId(i);
textview .setTextSize(15);
textview .setTextColor(Color.BLACK);
linear_layout.add(textview);
}
linear_layout.findViewById(1).setBackgroundColor(Color.RED);
Use getRandomColor method
Best Solution
To Genrate Light colors use this -
It show color like - https://stackoverflow.com/a/43235/4741746
To genrate Dark Color use this -