[英]Set TextView Text to the same color as the EditText fields Text Color
Essentially I have it set up where the EditText field gets populated onClick (of a cell in ListView) to a certain word. 从本质上讲,我设置了EditText字段,将onClick(位于ListView中单元格的位置)填充到某个单词。 I set that words color to green and it is green when present in the EditText field.
我将单词颜色设置为绿色,当出现在EditText字段中时为绿色。 Only issue is when I send that text to ListView, the text I set green in EditText is no longer green, it is the same color as the rest of the text.
唯一的问题是,当我将该文本发送到ListView时,在EditText中设置为绿色的文本不再是绿色,它与其余文本的颜色相同。 Anyone know of a solution for this?
有人知道解决方案吗?
public void onItemClick(AdapterView<?> a, View v, int position,
long id) {
int skull = R.drawable.image05;
Drawable image = getResources().getDrawable(skull);
if(images[imageId] == skull){
Toast.makeText(ChatRoom2.this, "Skull", Toast.LENGTH_LONG)
.show();
String next = "<font color='#13b602'>@Skull</font>";
editText.setText(Html.fromHtml(next));
editText.setSelection(editText.getText().length());
}
else{
Toast.makeText(ChatRoom2.this, "clicked", Toast.LENGTH_LONG)
.show();
}
The code above populates the EditText Field 上面的代码填充EditText字段
addButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// String message2;
message = editText.getText().toString();
RowItems item = new RowItems(images[imageId], message);
if (message.isEmpty()){
Toast.makeText(ChatRoom2.this, "Say Something", Toast.LENGTH_LONG)
.show();
}
else {
adapter.add(item);
adapter.notifyDataSetChanged();
}
editText.setText("");
//minimize keyboard bitch
InputMethodManager imm = (InputMethodManager)getSystemService(Context.
INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
});
The code above is when the message is sent to ListView 上面的代码是将消息发送到ListView时的代码
If you use editText.getText()
(instead of editText.getText().toString()
), and also change the type of message to CharSequence
, then it should keep whatever markup you applied. 如果您使用
editText.getText()
(而不是editText.getText().toString()
),并且还将消息的类型更改为CharSequence
,那么它应该保留您应用的任何标记。
By converting it into a string, you are losing this information. 通过将其转换为字符串,您将丢失此信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.