TextDrawable icon indicating copy to clipboard operation
TextDrawable copied to clipboard

Does not work with vinc3m1/RoundedImageView

Open byandby opened this issue 10 years ago • 12 comments

imageView = (RoundedImageView) findViewById(R.id.imageView1); int mineColor = getResources().getColor(R.color.thumbnail_bg_one); TextDrawable drawable; drawable = TextDrawable.builder().buildRoundRect("R", mineColor, 6); imageView.setImageDrawable(drawable);

The RoundedImageView only has a background but not text is draw.

byandby avatar Feb 09 '15 14:02 byandby

This is the same issue as issue#78. Quoted from the answer in isssue#78: "You don't need to use RoundedImageView since TextDrawable already supports rounded corners. Just use a normal ImageView."

jtadiarca avatar Mar 08 '15 00:03 jtadiarca

This is exactly what I was trying to Say Zeph.

caraus avatar Mar 29 '15 01:03 caraus

@ZephZeph what if I want to load the image from web, if not then use TextDrawable

rachitmishra avatar Jul 05 '15 18:07 rachitmishra

@byandby @ZephZeph @caraus @rachitmishra Hi, I am using CircleImageView which is a derivative of RoundedImageView, I have not been able to use this library because Bitmap#createBitmap thrown this exception. java.lang.IllegalArgumentException: width and height must be > 0 . Have you guys been able to find a solution to this while using the CircleImageView?

niteshreddy avatar Nov 20 '15 21:11 niteshreddy

ok! awesome, will use that!

rachitmishra avatar Nov 22 '15 08:11 rachitmishra

I've got it working with CircleImageView (https://github.com/hdodenhof/CircleImageView).

What I did was set the TextDrawable to a scale of the length/width of my CircleImageView. For example my CircleImageView is L:56 W:56. I set the TextDrawable to L:112 and W:112 and converted the TextDrawable to a bitmap. Then I passed the bitmap to the CircleImageView.

KtodaZ avatar Jan 13 '16 22:01 KtodaZ

@KtodaZ How exactly do you set L, W? setIntrinsicWidth(500) doesn't seem to work. Would you mind sharing your solution?

divonas avatar Oct 27 '16 12:10 divonas

Sure. Here is my code below:

 private final int circleImageViewWidth = 112;
 private final int circleImageViewTextSize = 60;
// Create drawable
TextDrawable drawable = TextDrawable.builder(this)
                .beginConfig()
                .useFont(Typeface.DEFAULT_BOLD)
                .fontSize(circleImageViewTextSize)
                .height(circleImageViewWidth)
                .width(circleImageViewWidth)
                .endConfig()
                .buildRound(Character.toString(firstName.charAt(0)).toUpperCase(), color);
// Convert to bitmap (generic solution found on stackoverflow)
if (drawable instanceof BitmapDrawable) {
            BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
            if(bitmapDrawable.getBitmap() != null) {
                return bitmapDrawable.getBitmap();
            }
        }

        if(drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
            bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel
        } else {
            bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        }

        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
        return bitmap;

and my recycler_text_view.xml

<de.hdodenhof.circleimageview.CircleImageView
                        android:id="@+id/circleImageView"
                        android:layout_width="56dp"
                        android:layout_height="56dp"
                        android:src="@drawable/ic_contact_picture" />

@divonas Hope this helps

KtodaZ avatar Oct 28 '16 05:10 KtodaZ

@KtodaZ Thank you for sharing.

divonas avatar Oct 28 '16 05:10 divonas

For anyone having problems with RoundedImageView, just set width and height in the TextDrawable builder. This way the RoundedImageView will be able to display it.

divonas avatar Oct 28 '16 12:10 divonas

@divonas you rock, setting the height and width is all that's needed. I'm using com.makeramen.roundedimageview.RoundedImageView

cobear25 avatar Apr 19 '17 19:04 cobear25

text color is not set even after setting the color alPha = TextDrawable.builder() .beginConfig() .height(40) .width(40) .useFont(ViewUtils.getMontesaratfont()) .textColor(R.color.white) .endConfig() .buildRound(letter, generator.getColor(position)); this is my code

shastrikikitchen avatar Dec 20 '17 17:12 shastrikikitchen