How to highlight selected text in android?
I have created Text View dynamically.I have to set focus/highlight the particular text when i click on that Text View.please suggest me how t开发者_如何学Pythono do this?
You could set a listener to control the desired behavior on the "click" event. Something like this:
textView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
v.setBackgroundColor(Color.GREEN);
}
});
If you want to deselect the selected TextView when you click in a new one, just change the background colors of the preciously selected TextView.
Android TextView's API here.
Hope it helps :D
int blue = 0xff0000ff;
int red = 0xffff0000;
text.setBackgroundColor(blue);
text.setTextColor(red);
Have you tried this:
TextView tv = (TextView) findVieById(R.id.my_textview); //replacing my_textview with the correct resource id
tv.setSelectAllOnFocus(true);
Try this
text.setFocusable(true);
also
text.requestFocus();
加载中,请稍侯......
精彩评论