android 输入表情icon

来源:互联网 发布:网络图标打不开怎么办 编辑:程序博客网 时间:2024/03/29 10:28

    1-输入框 插入表情     

   Bitmap bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.q);     ImageSpan imageSpan=new ImageSpan(this, bitmap);     SpannableString spannableString=new SpannableString("image");    spannableString.setSpan(imageSpan, 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);     //给输入框追加表情   editText.append(spannableString);  

     2- 给textview插入表情

  ImageSpan span = new ImageSpan(this, R.drawable.ic_launcher);  SpannableString spanStr = new SpannableString("http://www.baidu.com");  spanStr.setSpan(span, spanStr.length()-1, spanStr.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);  mTVText.setText(spanStr);

 3-修改textview局部文字颜色

  textView = (TextView) findViewById(R.id.textview);    SpannableStringBuilder builder = new SpannableStringBuilder(textView.getText().toString());      //ForegroundColorSpan 为文字前景色,BackgroundColorSpan为文字背景色    ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.RED);    ForegroundColorSpan whiteSpan = new ForegroundColorSpan(Color.WHITE);    ForegroundColorSpan blueSpan = new ForegroundColorSpan(Color.BLUE);    ForegroundColorSpan greenSpan = new ForegroundColorSpan(Color.GREEN);    ForegroundColorSpan yellowSpan = new ForegroundColorSpan(Color.YELLOW);    builder.setSpan(redSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);    builder.setSpan(whiteSpan, 1, 2, Spannable.SPAN_INCLUSIVE_INCLUSIVE);    builder.setSpan(blueSpan, 2, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);    builder.setSpan(greenSpan, 3, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);    builder.setSpan(yellowSpan, 4,5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);      textView.setText(builder); 



0 0
原创粉丝点击