【发布时间】:2014-06-13 18:36:11
【问题描述】:
我正在尝试创建标签,但仍然找不到单个登录。
Android 如何在我编写 android 时从像这个网站这样的文本创建标签,它是用十字按钮突出显示的?
谢谢
【问题讨论】:
标签: android
我正在尝试创建标签,但仍然找不到单个登录。
Android 如何在我编写 android 时从像这个网站这样的文本创建标签,它是用十字按钮突出显示的?
谢谢
【问题讨论】:
标签: android
你真的应该试着写出清晰易懂的问题。据我了解,您想要一个包含令牌的EditText。您可以使用许多开源库之一来执行此操作,例如:https://github.com/kpbird/chips-edittext-library。
【讨论】:
你可以这样做:
在xml中,提到了一个带有drawable的edittext:
<EditText
android:id="@+id/message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:inputType="text"
android:drawableRight="@drawable/ic_launcher"
>
</EditText>
将 textwatcher 添加到该 edittext 并检查其文本是否与一堆字符串中的任何一个匹配。如果是这样,只显示drawable,否则将drawable设置为null。
看这个:
EditText msg;
msg = (EditText) findViewById(R.id.message);
msg.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
msg.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
if (msg.getText().toString().equalsIgnoreCase("android"))
msg.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_launcher, 0);
else
msg.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
如果您想在另一个框中显示整个文本和图像(如显示标签),则需要自定义。
您可以参考this 处理edittext 中可绘制的点击事件。
希望这能给你一个开始。
【讨论】: