开发者

How to highlight selected text in android?

开发者 https://www.devze.com 2023-03-29 01:49 出处:网络
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 co

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号