So I have been browsing a lot and not seen anything that can help me, (yes I have seen the answer here) but it would not work with a random number(or if you could help me make it work would be amazing), if anyone could help me I am willing to offer a small paypal gift since this is driving me nuts. I will share what I'm trying currently and my list of colors
public void setNumberPickerTextColor(NumberPicker numberPicker, int color){
EditText et = ((EditText) numberPicker.getChildAt(0));
et.setTextColor(getResources().getColor(color));
}
this is my random color
private int [] textColours = new int[]{
R.color.text_color_1, R.color.text_color_2, R.color.text_color_3,
R.color.text_color_4, R.color.text_color_5, R.color.text_color_6,
R.color.text_color_7, R.color.text_color_8, R.color.text_color_9,
R.color.text_color_10
};
int randomColorPicker = (int)(Math.random() * textColours.length);
setNumberPickerTextColor(pickerOne, randomColorPicker);
So I used the link in the description with help from 0X0nosugar
Random rnd = new Random();
int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
//set the picker text color from the method below and the random number above
setNumberPickerTextColor(pickerOne, color);
setNumberPickerTextColor(pickerTwo, color);
setNumberPickerTextColor(pickerThree, color);
setNumberPickerTextColor(pickerTolerance, color);
and then using the answer from the link above this will randomly generate a random color everytime
Related
here's my code but using this the color changes for the whole progressbar
Random rnd = new Random();
int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
progressBar.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
int greyColor= Color.rgb(248,248,248);
i want to add random colors to the text avatars in place of a single blue color
enter image description here
my list code is this
list = new ArrayList<>();
for(int i =0;i<data.length();i++){
ModelFriendList temp = new ModelFriendList();
temp.setName(data.getJSONObject(i).getString("name"));
temp.setUsername(data.getJSONObject(i).getString("phone"));
temp.setID(data.getJSONObject(i).getInt("UID"));
list.add(temp);
}
Add getter setter method of RandomColor in your model and add below code and in your item set background color from your model.
for(int i =0;i<data.length();i++){
Random rnd = new Random();
int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
ModelFriendList temp = new ModelFriendList();
temp.setName(data.getJSONObject(i).getString("name"));
temp.setUsername(data.getJSONObject(i).getString("phone"));
temp.setID(data.getJSONObject(i).getInt("UID"));
temp.setRandomColor(color);
list.add(temp);
}
You can get random color by using Random class
Random random = new Random();
int color = Color.argb(255, random .nextInt(256), random .nextInt(256), random .nextInt(256));
After that you can set these color inside your model and get it when you want to set it on the view i.e avatar.
I am currently working on an android APP and I have a list of predefined color in my colors.xml.
Now what I want to achieve is that I want to give the user the opportunity of selecting a color and from the color the user select, I want to display various color (randomly) in the background that matches the global color the user selects, such that those colors will be changing at interval. These colors that will be displayed randomly are already defined in my colors.xml file
Any Guidance or a lead sample on this requirement will be invaluable.
Thank you in advance
private int[] colors = {Color.RED, Color.YELLOW, Color.BLUE, Color.CYAN, Color.GREEN};
Random ranndom = new Random();
int ranndomColor = ranndom.nextInt(5);
whatever.setBackground(colors[ranndomColor]);
or get the colors from "colors.xml:
int color1 = getResources().getColor(R.color.color1);
int color2 = getResources().getColor(R.color.color2);
int color3 = getResources().getColor(R.color.color3);
int color4 = getResources().getColor(R.color.color4);
int color5 = getResources().getColor(R.color.color5);
private int[] colors = {color1, color2, color3, color4, color5};
Random ranndom = new Random();
int ranndomColor = ranndom.nextInt(5);
whatever.setBackground(colors[ranndomColor]);
I'm a bit stuck here. I have a graph but next to the graph I would love to put a textview.
The textView should get my records straight from the database and add a colour code to it.
(For now a simple for loop will do)
I've got to the point that the pie chart gets drawn and a textview next to the pie chart shows all strings printed (which is now test + the number from the array)
protected void createPiechart(){
Number[] seriesOfNumbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int teller = 0, teller2 = 0;
String text= "";
PieGraph pg = (PieGraph) findViewById(R.id.piegraph);
for (teller = 0; teller < seriesOfNumbers.length;) {
//Random colors in the whole range
Random randomFullRange = new Random();
int color = Color.argb(255, randomFullRange.nextInt(256), randomFullRange.nextInt(256), randomFullRange.nextInt(256));
teller2 = 100 + (15 * teller);
seriesOfNumbers[teller] = teller;
PieSlice slice = new PieSlice();
//Random colors only in green tints.
//Random rnd = new Random();
//int color = Color.argb(255, 0, teller2, 0);
slice.setColor(color);
slice.setValue(teller);
slice.setTitle("test");
pg.addSlice(slice);
text += "test " + teller + "\n";
teller++;
}
TextView textPieGraph = (TextView) findViewById(R.id.textPieGraph);
textPieGraph.setText(text);
}
Now I would like to add the colour that the pieslice has in the textview in some sort of bitmap (lets say 20px*20px)
Which would give
Bitmap Categoryname1
Bitmap2 Categoryname2
... etc etc.
Now how could I add bitmaps to it dynamically with the same colours of my int color value?
I'd love a colour coded list with the text.
Thanks
Yenthe
You could set the background of the textview to the color or add a bitmap behind the text.
textPieGraph.setBackgroundColor(Color.blahblah);
If you wanted it beside it (which might be easier for the user) in a smaller form you could add a linearlayout horizontal around the textview and put a small view beside it and color the background in it. This way there could be the color square beside the text.
I have a ImageView where I put a Bitmap (left), sometimes I wanna see bitmap with a semitransparent blue layer (right). I try with a ColorFilter (LightingColorFilter and PorterDuffColorFilter) but I get a dark blue, how can I do this with ColorFilter or anything else?
Thanks.
EDIT (I tried this and other variants)
//ColorFilter filter = new PorterDuffColorFilter(color.wather, PorterDuff.Mode.DST_OVER);
ColorFilter filter = new LightingColorFilter(color.mul, color.wather);
// mul = 0xFFFFFFFF and wather = 0x7000FFFF
BitmapScaler scaler = new BitmapScaler();
imagen.setImageBitmap(scaler.getScaled());
imagen.setColorFilter(filter);
I tried diferents mul, add values and always get this:
I've already finds the mul, add values, I had a problem with color.xml because I used ID number instead the color RGB number, big mistake. Transparence (Alpha) are ignore but I can get the effect downing intensity of add value.
int mul = 0xFFFFFF;
int add = 0x005050;
filter = new LightingColorFilter(mul, add);
Thanks Elior for your help.