Edittext input emoticon image. read Lao Luo Android notes

Source: Internet
Author: User
 
<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Orientation = "vertical"> <! -- Chat input --> <edittext Android: Id = "@ + ID/et_chat" Android: layout_width = "300dip" Android: layout_height = "wrap_content"/> <button Android: id = "@ + ID/bt_insetface" Android: layout_width = "50dip" Android: layout_height = "wrap_content" Android: text = "insert tag"/> </linearlayout>

 




EditTextFaceActivity .java
Package CN. face; import Java. lang. reflect. field; // reflect reflection import Java. util. random; import android. app. activity; import android. graphics. bitmap; import android. graphics. bitmapfactory; import android. graphics. drawable. bitmapdrawable; import android. OS. bundle; import android. text. spannable; import android. text. spannablestring; import android. text. style. imagespan; import android. view. view; import android. view. view. onclicklistener; import android. widget. button; import android. widget. edittext; public class edittextfaceactivity extends activity {private edittext et_chat; private button bt_insetface; Public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); et_chat = (edittext) findviewbyid (R. id. et_chat); bt_insetface = (button) findviewbyid (R. id. bt_insetface); bt_insetface.setonclicklistener (New onclicklistener () {public void onclick (view v) {int randomid = 1 + new random (). nextint (20); try {field = R. drawable. class. getdeclaredfield ("face" + randomid); int resourceid = integer. parseint (field. get (null ). tostring (); // display the image information in Android. Bitmap bitmap must be used to load bitmap = bitmapfactory. decoderesource (getresources (), resourceid); imagespan = new imagespan (edittextfaceactivity. this, bitmap); spannablestring = new spannablestring ("face"); // the prefix of the emoticon image is "face" spannablestring. setspan (imagespan, 0, 4, spannable. span_exclusive_exclusive); et_chat.append (spannablestring);} catch (exception e ){}}});}}

  

 

 

 

 

View implementation Images

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.