是否可以在选择器中使用字体图标而不是绘图?
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/menu_home_press" android:state_pressed="true"></item>
<item android:drawable="@drawable/menu_home"></item>
</selector>发布于 2016-02-08 14:15:50
您可以使用字体-令人敬畏的图标如下:
将字体-令人敬畏的字体文件复制到资产目录
2-使用这页面为我想要的图标找到字符实体
3-在strings.xml中为每个图标创建条目。例:
<string name="icon_eg"></string>4-在onCreate方法中加载字体并将其设置为适当的视图:
Typeface font = Typeface.createFromAsset( getAssets(), "fontawesome-webfont.ttf" );
...
Button button = (Button)findViewById( R.id.like );
button.setTypeface(font);不要忘记引用视图中的字符串。
<Button
android:id="@+id/my_btn"
style="?android:attr/buttonStyleSmall"
...
android:text="@string/icon_eg" />有关更多信息,请查看这链接。
你不能用它作为选择器。但是您可以动态地更改图标。
https://stackoverflow.com/questions/35271608
复制相似问题