以编程方式更改android edittext中的文本颜色

时间:2013-10-08 12:37:04

标签: android android-edittext textcolor

我必须为edittext创建背景颜色,这意味着我正确地获得了背景。

 TestPost.this.findViewById(R.id.revieew)  
            .setBackgroundColor(color);  

但是我怎么能得到这些edittext的textcolor。

 TestPost.this.findViewById(R.id.revieew)  
            .setTextColor(color); 

请给我一个解决方案???

我必须选择绿色意味着必须输入文本是绿色....这里我已经为背景颜色做了这些。我必须设置背景颜色是绿色意味着必须从颜色选择器中选择颜色绿色意味着bexkground成功显示...我如何设置颜色选择器的文本颜色???

修改

reviewEdit.setTextColor(color);

意味着我的颜色成功了...但我并没有改变整个文本。

我想单独更改所选文字的颜色......

对于EG:

文字是:客户正在等待您的回复意味着

必须选择一个绿色,必须写出客户正在等待这些文本单独显示绿色。之后必须选择一个粉红色的手段必须显示为您的回复为粉红色。

这正是我需要的......我怎样才能实现这些???

4 个答案:

答案 0 :(得分:4)

((TextView)TestPost.this.findViewById(R.id.revieew)).setTextColor(color);

See the docs here

答案 1 :(得分:2)

你在做什么几乎是正确的。方法findViewById()返回一个View,您需要将其强制转换为TextView / EditText(取决于您在xml中定义具有该id的视图的方式),然后该方法可供使用。

EditText text = (EditText) findViewById(R.id.revieew);
text.setTextColor(color);

答案 2 :(得分:1)

试试这个TestPost.this.findViewById(R.id.revieew).getCurrentTextColor();

在此处找到:https://stackoverflow.com/a/6746131/2065418

答案 3 :(得分:1)

您的方法在代码

下方获取颜色是正确的
int color =editText.getCurrentTextColor();
    Log.d("color", String.valueOf(color));
相关问题