如何使用 fontawesome 设置标记图标
How to set Marker icon using fontawesome
Drawable iconmarker = FontIconDrawable.inflate(context, R.xml.ic_red_marker);
Bitmap bitmap = ((BitmapDrawable) iconmarker).getBitmap();
driver_marker = googleMap.addMarker(new MarkerOptions()
.position(latLng)
.icon(BitmapDescriptorFactory.fromBitmap(bitmap)));*/
ic_red_marker.xml 文件
<?xml version="1.0" encoding="utf-8"?>
---- font-icon
xmlns:android="http://schemas.android.com/apk/res-auto"
android:text="@string/icon_marker"
android:textSize="@dimen/icon_size"
android:textColor="@android:color/white"/>
字体很棒的代码
<string name="icon_marker"></string>
错误
line- Bitmap bitmap = ((BitmapDrawable) iconmarker).getBitmap();
Caused by: java.lang.ClassCastException:
com.shamanland.fonticon.FontIconDrawable cannot be cast to
android.graphics.drawable.BitmapDrawable
您可以如下设置 IconDrawable :
IconDrawable drawable = new IconDrawable(this, IconValue.fa_home).colorRes(R.color.ab_item)
.actionBarSize())
现在您可以将 IconDrawable 设置为 Imageview,如下所示:
imageview.setImageDrawable(drawable);
现在,如果您想要位图,请尝试
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
为此,您需要将 android-iconify jar 添加到您的 libs 文件夹中。
参考:
1) https://github.com/JoanZapata/android-iconify
2) http://www.java2s.com/Code/Jar/a/Downloadandroidiconifysample101jar.htm
希望对您有所帮助。
Drawable iconmarker = FontIconDrawable.inflate(context, R.xml.ic_red_marker);
Bitmap bitmap = ((BitmapDrawable) iconmarker).getBitmap();
driver_marker = googleMap.addMarker(new MarkerOptions()
.position(latLng)
.icon(BitmapDescriptorFactory.fromBitmap(bitmap)));*/
ic_red_marker.xml 文件
<?xml version="1.0" encoding="utf-8"?>
---- font-icon
xmlns:android="http://schemas.android.com/apk/res-auto"
android:text="@string/icon_marker"
android:textSize="@dimen/icon_size"
android:textColor="@android:color/white"/>
字体很棒的代码
<string name="icon_marker"></string>
错误
line- Bitmap bitmap = ((BitmapDrawable) iconmarker).getBitmap();
Caused by: java.lang.ClassCastException: com.shamanland.fonticon.FontIconDrawable cannot be cast to android.graphics.drawable.BitmapDrawable
您可以如下设置 IconDrawable :
IconDrawable drawable = new IconDrawable(this, IconValue.fa_home).colorRes(R.color.ab_item)
.actionBarSize())
现在您可以将 IconDrawable 设置为 Imageview,如下所示:
imageview.setImageDrawable(drawable);
现在,如果您想要位图,请尝试
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
为此,您需要将 android-iconify jar 添加到您的 libs 文件夹中。
参考:
1) https://github.com/JoanZapata/android-iconify
2) http://www.java2s.com/Code/Jar/a/Downloadandroidiconifysample101jar.htm
希望对您有所帮助。