1

I am developing an Android app. In my app, I want to play with icons. So I tried to import icons to my project like we import font-awesome in web development. So I searched online and I followed this link: How to import set of icons into Android Studio project.

After I install it, I restarted Android Studio. When I search android importer plugin under other settings, I cannot find it. See my screenshot below.

enter image description here

I am pretty sure I installed it successfully. See the screenshot below.

enter image description here

So why I cannot find it? How can I import icons to my project in Android Studio? I am using Android Studio 1.4.

halfer
  • 19,824
  • 17
  • 99
  • 186
Wai Yan Hein
  • 13,651
  • 35
  • 180
  • 372

2 Answers2

2

I use the mikepenz library to use font-awesome icons

https://github.com/mikepenz/Android-Iconics

add the file build.gradle

compile 'com.mikepenz:fontawesome-typeface:4.5.0.1@aar'

example xml

       <com.mikepenz.iconics.view.IconicsImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="2"
                android:id="@+id/img_addCart"
                app:iiv_size="25dp"
                app:iiv_color="@color/md_blue_grey_300"
                app:iiv_icon="faw-cart-arrow-down" />

or the code

icon = new IconicsDrawable (getContext ())
                     .icon (FontAwesome.Icon.faw_star)
                     .color (ContextCompat.getColor 
                           (getContext () R.color.md_yellow_600))
                     .sizeDp (25);

             ((IconicsImageView) view) .setIcon (icon)
Marco Giovanni
  • 297
  • 7
  • 18
  • But what I want is drawable resource. How can I get it? For example, for setting drawableLeft . – Wai Yan Hein Apr 06 '16 at 13:45
  • Thanks. It is awesome. But I still have a problem. I installed font-awesome, I can I set Icon for textView usiing placeholder. I followed instructions and not working. Please show me example of setting icon for text view in xml please. – Wai Yan Hein Apr 06 '16 at 14:04
  • Never used in textview using placeholder, I'll do some tests to see if I can make it work :) – Marco Giovanni Apr 06 '16 at 15:42
  • Lie, I used yesterday ... I posted the lowest code for you to see – Marco Giovanni Apr 06 '16 at 15:50
0

I've used in textview thus:

    SpannableStringBuilder ssb = new SpannableStringBuilder( "My String   contains one icon." );

    Bitmap fvorito = new IconicsDrawable(getContext(), FontAwesome.Icon.faw_star_o)
            .sizeDp(25)
            .color(ContextCompat.getColor(getContext(), R.color.md_blue_grey_300))
            .toBitmap();

     //ImageSpan imageSpan = new ImageSpan(null, fvorito, ImageSpan.ALIGN_BOTTOM);
    ImageSpan imageSpan = new CenteredImageSpan(null, fvorito, ImageSpan.ALIGN_BOTTOM);

    ssb.setSpan( imageSpan, 10, 11, Spannable.SPAN_INCLUSIVE_INCLUSIVE );
    txtDescricao.setText( ssb, TextView.BufferType.SPANNABLE );

I do not know if I could help you

CenteredImageSpan is class

public class CenteredImageSpan extends ImageSpan {

    //http://stackoverflow.com/questions/25628258/align-text-around-imagespan-center-vertical

    public CenteredImageSpan(Context context, Bitmap b, int verticalAlignment) {
        super(context, b, verticalAlignment);
    }

    @Override
    public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
        Drawable b = getDrawable();
        canvas.save();

        int transY = bottom - b.getBounds().bottom;
        // this is the key
        transY -= paint.getFontMetricsInt().descent / 2;

        canvas.translate(x, transY);
        b.draw(canvas);
        canvas.restore();
    }
}

Output:

output

Marco Giovanni
  • 297
  • 7
  • 18