标签中的EditText

我想复制标记用户,而在之后编辑文本输入他的名字命名的功能,输入用户名,当用户“@”进入标签中的EditText

请参阅所附的图像正是我想要什么做

下面部的Sally Jones标记,而从编辑的文本输入他的名字克里斯remkes。

任何建议如何做到这一点,所以当这个名字被点击时,我可以显示用户的详细信息。

回答:

您可以使用ClickableSpan:

SpannableString textString = new SpannableString("Great video @ChrisRemkes I'm making a similar one but I think it could do with some editing like your one!!!"); 

ClickableSpan clickableSpan = new ClickableSpan() {

@Override

public void onClick(View textView) {

Toast.makeText(getApplicationContext(), "The text '@ChrisRemkes' has been clicked. Do something.",

Toast.LENGTH_SHORT).show();

}

@Override

public void updateDrawState(TextPaint ds) {

super.updateDrawState(ds);

// NOTE: here's where you can set the styling give UI feedback that this is text that can be clicked on.

ds.setColor(getResources().getColor(android.R.color.holo_blue));

}

};

// NOTE: you will need to setup getStartPositionOfTag(textString) and getEndPositionOfTag(textString) to pattern match on the textString to find the start position and end position of @ChrisRemkes

textString.setSpan(clickableSpan, getStartPositionOfTag(textString), getEndPositionOfTag(textString), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

textView.setText(textString);

textView.setMovementMethod(LinkMovementMethod.getInstance());

以上是 标签中的EditText 的全部内容, 来源链接: utcz.com/qa/266739.html

回到顶部