久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

聯系氣泡編輯文本

Contact Bubble EditText(聯系氣泡編輯文本)
本文介紹了聯系氣泡編輯文本的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試在 MultiAutoCompleteTextView 中創建聯系人氣泡,類似于它在 Google+ 應用中的實現方式.下面是截圖:

I am trying to create contact bubbles in the MultiAutoCompleteTextView similiar to how it is implemented in the Google+ app. Below is a screen shot:

.

我試圖擴展 DynamicDrawableSpan 類,以便在一段文本的背景中獲得一個可擴展的可繪制對象

I have tried to extend the DynamicDrawableSpan class in order to get a spannable drawable in the background of a span of text

public class BubbleSpan extends DynamicDrawableSpan {
  private Context c;

  public BubbleSpan(Context context) {
    super();
    c = context;
  }

  @Override
  public Drawable getDrawable() {
    Resources res = c.getResources();
    Drawable d = res.getDrawable(R.drawable.oval);
    d.setBounds(0, 0, 100, 20);
    return d;
  }
}

我的橢圓形.xml 可繪制對象是這樣定義的:

Where my oval.xml drawable is defined as so:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
  <solid android:color="#352765"/>
  <padding android:left="7dp" android:top="7dp"
    android:right="7dp" android:bottom="7dp" />
  <corners android:radius="6dp" />
</shape>

在具有 MulitAutoCompleteTextView 的 Activity 類中,我將氣泡跨度設置如下:

In my Activity class that has the MulitAutoCompleteTextView, I set the bubble span like so:

final Editable e = tv.getEditableText();
final SpannableStringBuilder sb = new SpannableStringBuilder();
sb.append("some sample text");
sb.setSpan(new BubbleSpan(getApplicationContext()), 0, 6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
e.append(sb); 

但是,在字符串的前 6 個字符后面顯示的不是橢圓形,而是字符不可見,并且背景中沒有可繪制的橢圓形.

However, instead of the oval shape displaying behind the first 6 characters in the string, the characters are not visible and there is no oval drawable in the background.

如果我將 BubbleSpan 的 getDrawable() 方法更改為使用 .png 而不是可繪制的形狀:

If i change the BubbleSpan's getDrawable() method to use a .png instead of a shape drawable:

public Drawable getDrawable() {
  Resources res = c.getResources();
  Drawable d = res.getDrawable(android.R.drawable.bottom_bar);
  d.setBounds(0, 0, 100, 20);
  return d;
}

然后 .png 將顯示,但作為 span 的一部分的字符串中的字符將不會顯示.如何使 span 中的字符顯示在前景中,同時自定義形狀 drawable 顯示在背景中?

Then the .png will show up but the characters in the string that are a part of the span will not show up. How can I make it so that the characters in the span are displayed in the foreground, meanwhile a custom shape drawable gets displayed in the background?

我也嘗試使用 ImageSpan 而不是子類化 DynamicDrawableSpan 但沒有成功.

I attempted to also use an ImageSpan instead of subclassing DynamicDrawableSpan but was unsuccessful.

推薦答案

感謝@chrish 的所有幫助.所以我是這樣做的:

Thanks @chrish for all the help. So here is how i did it:

final SpannableStringBuilder sb = new SpannableStringBuilder();
TextView tv = createContactTextView(contactName);
BitmapDrawable bd = (BitmapDrawable) convertViewToDrawable(tv);
bd.setBounds(0, 0, bd.getIntrinsicWidth(),bd.getIntrinsicHeight());

sb.append(contactName + ",");
sb.setSpan(new ImageSpan(bd), sb.length()-(contactName.length()+1), sb.length()-1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
to_input.setText(sb);

public TextView createContactTextView(String text){
  //creating textview dynamically
  TextView tv = new TextView(this);
  tv.setText(text);
  tv.setTextSize(20);
  tv.setBackgroundResource(R.drawable.oval);
  tv.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_clear_search_api_holo_light, 0);
  return tv;
}

public static Object convertViewToDrawable(View view) {
  int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
  view.measure(spec, spec);
  view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
  Bitmap b = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(),
            Bitmap.Config.ARGB_8888);
  Canvas c = new Canvas(b);
  c.translate(-view.getScrollX(), -view.getScrollY());
  view.draw(c);
  view.setDrawingCacheEnabled(true);
  Bitmap cacheBmp = view.getDrawingCache();
  Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
  view.destroyDrawingCache();
  return new BitmapDrawable(viewBmp);

}

這篇關于聯系氣泡編輯文本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event(EditText:禁用文本選擇處理程序單擊事件上的粘貼/替換菜單彈出)
Multiline EditText with Done SoftInput Action Label on 2.3(2.3 上帶有完成 SoftInput 操作標簽的多行 EditText)
How to detect the swipe left or Right in Android?(如何在 Android 中檢測向左或向右滑動?)
Prevent dialog dismissal on screen rotation in Android(防止在Android中的屏幕旋轉對話框解除)
How do I handle ImeOptions#39; done button click?(如何處理 ImeOptions 的完成按鈕點擊?)
How do you set EditText to only accept numeric values in Android?(您如何將 EditText 設置為僅接受 Android 中的數值?)
主站蜘蛛池模板: 欧美成人精品一区二区男人看 | 黄色在线播放视频 | 高清亚洲 | 日日夜夜精品视频 | 久久国产精品久久国产精品 | 日韩和的一区二在线 | 国产一二三区免费视频 | 久久久久久久99 | 亚洲毛片| 亚洲视频一区在线观看 | 国产十日韩十欧美 | 成人精品网 | 天天操妹子 | 97人人澡人人爽91综合色 | 亚洲天堂网站 | www.成人免费视频 | 亚洲午夜视频 | 中国大陆高清aⅴ毛片 | 午夜精品在线 | 国产午夜精品视频 | 天堂成人国产精品一区 | 亚洲精品一区二区 | 91在线精品播放 | 久久久久久亚洲精品 | www.成人.com| 成人av影院 | 91黄色免费看| 欧美日韩中文字幕在线 | 综合久| 一级aaaaaa毛片免费同男同女 | 亚洲在线一区二区 | 国产激情视频在线免费观看 | 亚洲国产一区二区三区四区 | 懂色中文一区二区三区在线视频 | 人人草天天草 | 99精品一区二区三区 | 中文字幕动漫成人 | 宅女噜噜66国产精品观看免费 | 色综合久久天天综合网 | 国产精品 欧美精品 | 在线黄色网 |