imagespan

How to apply the background color for the ImageSpan in Android?

為{幸葍}努か 提交于 2020-03-02 12:22:28
问题 I want to apply the background color for the Image span dynamically in Android. Could you please suggest any ideas? 回答1: You can't use BackgroundColorSpan and ImageSpan at the same time. The idea is creating an ImageSpan from LayerDrawable with background and image layers. Please look at the following code: Kotlin: val span: Spannable = SpannableString("This is ic launcher with background") val myImage: Drawable = resources.getDrawable(R.drawable.ic_launcher_foreground) val background =

ImageSpan Size Measurement with TextView and StaticLayout

北战南征 提交于 2020-01-07 06:24:34
问题 I have a simple layout contains just one TextView . I wanna load an image into TextView using ImageSpan. Below method creates Spannable : private Spannable getImageSpannable(int drawableId, int targetWidth, int targetHeight) { Bitmap originalBitmap = BitmapFactory.decodeResource(getResources(), drawableId); Bitmap bitmap = Bitmap.createScaledBitmap(originalBitmap, targetWidth, targetHeight, true); Drawable dr = new BitmapDrawable(getResources(), bitmap); dr.setBounds(0, 0, bitmap.getWidth(),

How to handle onClick event on imageSpan in editText?

大憨熊 提交于 2020-01-02 02:28:05
问题 i am working on an app in which user choose an image from gallery and it will be added in editText, now i want if user click on image in editText it should open in fullScreen, i used below code :- public void addToEdt(Bitmap bitmap){ SpannableString ss = new SpannableString("abc"); Drawable d = new BitmapDrawable(getResources(), bitmap); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE); ss.setSpan(span, 0, 3,

TextView with ImageSpan messes up line height

天大地大妈咪最大 提交于 2020-01-01 12:31:34
问题 I have a TextView filled with text that should contain some ImageSpan objects. The images can be taller than the normal line height which causes the following problem: if the image is the last object of a line, the following lines' height is correct if the last object is not an image, the following lines' height is set to the image-containing line's height Here is the correct situation: This is the wrong situation: What's more interesting is that if there's a new-line character in the text,

ImageSpan not working on Android 5

纵饮孤独 提交于 2020-01-01 08:53:46
问题 I have this function that works fine on Android 4.4.1, but breaks on 5.0+. public static SpannableStringBuilder prependImage(Drawable drawable, String text) { SpannableStringBuilder builder = new SpannableStringBuilder(" " + text); builder.setSpan(new ImageSpan(drawable), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return builder; } And I use it like this: class MyButton extends Button { // ... snip ... setText( prependImage( getDrawable(imageResource, color), getContext().getString

Insert line separator in spannablestringbuilder after imagespans (Android)

孤街浪徒 提交于 2019-12-24 06:39:46
问题 I have a spannablestringbuilder with a number of imagespans in it. I would like to insert a line separator after the image to ensure that text following it starts on the next line. I am trying to do this in a loop, but it doesn't insert the line seprator and breaks the spans. ImageSpan[] imageSpans = strBuilder.getSpans(0, strBuilder.length(), ImageSpan.class); for (ImageSpan imageSpan : imageSpans) { strBuilder = strBuilder.insert(strBuilder.getSpanEnd(imageSpan), System.getProperty("line

android imagespan image is cut error in singleline textview

筅森魡賤 提交于 2019-12-19 11:37:12
问题 I use ImageSpan to display image in textview. The TextView is sinlgline with end ellipsize. When image is in the end of textview and there is not enought space for it. I think it should display "...". But it display part of Image . The image is clipped in error. the xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen

Clicking on ClickableSpan in CheckBox changes its state

送分小仙女□ 提交于 2019-12-12 13:21:20
问题 I've got an ImageSpan and ClickableSpan in my checkbox to display icon at the end of checkbox text and handle clicking on it. But clicking on it changes checkbox checked state, which is not needed. How can I prevent changing checkbox state when user clicks on ClickableSpan? Simply I need some equivalent of cancelPendingInputEvents() method for API 16+. Also I don't want to separate checkbox with checkbox and textview. 回答1: Are you using a solution similar to that outlined in https:/

Delete entire ImageSpan when the part of it is deleted

非 Y 不嫁゛ 提交于 2019-12-11 17:16:43
问题 I'm trying to implement Emoji's in my app and I should use short codes (like :dog: , :cat: ), not unicode. I have two devices to test on and two different behaviours of EditText and ImageSpan in it. First: Meizu PRO 6, Android 6.0 (API 23) Everything works as I want. When you tap backspace on the spanned text, it disappears from EditText completely, because full spanned part of the string was removed. For example, you have a "Hello :dog: " in your EditText ( :dog: is replaced with a picture

Cannot Set Image and Text in Center Vertical Android PagerTabStrip Android

自作多情 提交于 2019-12-11 10:58:19
问题 I got problem when I try to set image and text vertically center. So I'm using SpannableStringBuilder and ImageSpan. I try to combile image and text by this code : @Override public CharSequence getPageTitle(int position) { Locale l = Locale.getDefault(); Drawable drawableIcon = null; // space added before text for convenience SpannableStringBuilder sb = new SpannableStringBuilder(" "); ImageSpan span = null; switch (position) { case 0: drawableIcon = getResources().getDrawable(R.drawable.ic