I have to create the background color for edittext means am getting the background correctly.
TestPost.this.findViewById(R.id.revieew)
.setBackgroundColor(color);
But how can i get the textcolor for these edittext .
TestPost.this.findViewById(R.id.revieew)
.setTextColor(color);
Please give me a solution ???
i have to pick the green color means have to enter the text is green....here i have done these for background color.i have to set the background color is green means have to pick the color green from color picker means the bexkground is successfully displaying...how can i set the textcolor from color picker ???
EDIT:
reviewEdit.setTextColor(color);
means am getting the color is successfully...But i didn't change the whole text.
I want to change the color for selected text alone...
For EG:
The text is : The customer is waiting for your reply means
Have to pick a color green, have to write the The customer is waiting have to display green color for these text alone.after that have to pick a color pink means have to display the for your reply as pink color.
This is exactly i need ...how can i implement these ???
((TextView)TestPost.this.findViewById(R.id.revieew)).setTextColor(color);
See the docs here
What you are doing is almost correct. The method findViewById() returns a View which you need to cast into a TextView/EditText (depending on how you have the view with that id defined in your xml) and then the method will be available for use.
EditText text = (EditText) findViewById(R.id.revieew);
text.setTextColor(color);
Try this TestPost.this.findViewById(R.id.revieew).getCurrentTextColor();
Found here: https://stackoverflow.com/a/6746131/2065418
Your method was correct for getting the color use below code
int color =editText.getCurrentTextColor();
Log.d("color", String.valueOf(color));
Related
I am developing an Android App where I have a few EditTexts. I am setting the background color of the EditText dynamically with the one I have defined in the res/drawable folder. I want to get the background color of the EditText and compare it with some hex color, e-g if the color is #ff0000 then change the text color of that EditText to white. This is how I am setting the background color of the EditText:
allScaleEditTexts.get(row_col).setBackgroundResource
(R.drawable.edittext_bgcolor_one);
That is how I am getting the background color of the EditText:
Drawable scaleEdTxtColor = allScaleEditTexts.get(row_col)
.getBackground();
Now I want to make that comparison like:
if(scaleEdTxtColor == #ff0000)
allScaleEditTexts.get(row_col).setTextColor(Color.WHITE);
else
allScaleEditTexts.get(row_col).setTextColor(Color.BLACK);
I don't know how to go about that comparison. I have tried this:
if(scaleEdTxtColor == Color.parseColor("#FF0000"))
But then I get the error of comparing a drawable with an int. How can I solve it?
You can't just use
if(scaleEdTxtColor == #ff0000)
Cause its a drawable.
I think you need to scaledEdTxtColor.getColorFilter like you set the color with:
scaledEdTxtColor.setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
Have a look there.
I am trying to change the text color of a RadioButton (which is
defined in an xml layout and is in a RadioGroup) on selecting it.
When I change the text color directly in the Eclipse Android Layout
Editor by setting the TextColor property to "#color/red" (which I
defined in strings.xml), it works just fine, but when I try to do this
programmatically during runtime as
myRadioButton.setTextColor(R.color.red);
it only turns the color to grey, not to red as intended.
R.color.red (#color/red) is correctly defined as a hex value
("#FF0000"), but it does turn the text color to red in the
layout editor, but not via a Java command.
if your color.xml is like:
<color name="errorColor">#f00</color>
and then use this code to show it:
myRadioButton.setTextColor(getResources().getColor(R.color.red));
there are some other ways to do so
myRadioButton.setTextColor(Color.RED);
or
myRadioButton.setTextColor(Color.rgb(red, green, blue));
// where red green and blue are the int values
edited if you want to get from resources then use
getResources().getColor(R.color.red) ;
I'm trying to change a color of a button in code as below
btn_no5.setTextColor(0x8E35EF);
the above change is not reflecting(purple color), the text is disappearing after execution of above piece of code. But if i use the color in xml its reflecting. So how to change this through java ?
The color you are using is fully transparent. Use 0xFF8E35EF instead. The first byte is the alpha (transparency) channel.
use like this,
btn_no5.setTextColor(Color.parseColor("#8E35EF"));
I can set my text color using heading.setTextColor(Color.RED); but I cant seem to find reference anywhere on how to set the background color of the Form/Screen.
Use setBackgroundColor
I got the info from http://developer.android.com/reference/android/view/View.html#setBackgroundColor
How do you change the color contrast of text when the background changes? for example If I was to have a black background, black text would not be visible.
This might be helpful: http://developer.android.com/guide/topics/resources/color-list-resource.html
It is a way you can set a color that will change based on certain circumstances.
For example, say you have a TextView that you want to have white text while it is enabled and black text when it is disabled. You can set that up in a xml file using the references in the link above, and then in your xml layout where you define the TextView set the android:textColor to #color/my_text_color. (my_text_color being the xml color list file you created)
Then, as the TextView changes from enabled to disabled (or whatever you end up setting up in the xml file) the color will change automatically as well.
That's one way to do it. However, you might want to try to clarify what you are looking for as it isn't perfectly clear in your question.
Update
After Matt's comment, here is a method you could use to get an inverted color value. There is probably a better way but this should work.
private int getInverseColor(int color){
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
int alpha = Color.alpha(color);
return Color.argb(alpha, 255-red, 255-green, 255-blue);
}
You could programmaticly get the color int from a view such as a TextView using one of the getTextColor() methods. You may have to tinker with a Color State List like I linked to above to get the color you want. Then pass that color to the method above to get the inverted color int and set it with one of the setTextColor() methods.