创建编辑文本标记? [英] Create tags in edit text?

查看:101
本文介绍了创建编辑文本标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建标签,但仍然无法找到单一的登录为。

I am trying to create tags but still cant find single login for that .

Android的我怎么能这样从网站的文本创建标签,当我写的android是showig突出了十字按键?

Android how I can create tag from a text like this site when I write android it is showig highlighted with cross button ?

感谢

推荐答案

您可以做这样的事情:

在XML中,有提到绘制一个EditText:

In xml, an edittext with a drawable mentioned:

<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上,并检查其文本是否匹配任何一串字符串的。如果是这样,只显示绘制,否则设置绘制为null。

Add textwatcher to that edittext and check its text if that matches any of a bunch of String. If so, just show the drawable, else set the drawable to 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

    }
});

您将需要定制,如果你想类似这样的标记显示在另一个盒子整个文本和图像。

You would need to customize if you want the whole text and image in another box like a tag is shown.

您可以参考<一个href=\"http://stackoverflow.com/questions/3554377/handling-click-events-on-a-drawable-within-an-edittext\">this用于处理绘制里​​面的EditText的click事件。

You can refer this for handling of click event of a drawable inside edittext.

希望这给你一个开始。

这篇关于创建编辑文本标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆