简体   繁体   中英

changing textcolor in android edittext programmatically

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

在这里查看文档

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM