iconFont(字体图标)上
来源:互联网 发布:xbox one 游戏 淘宝 编辑:程序博客网 时间:2024/06/05 09:23
为什么是上呢,因为我网上找的封装,感觉不是很好用,朋友说明天到单位,给我发一下,如果发来的好,就有下,如果没有感觉到特别好用,就太监了
本文参考于
https://www.jianshu.com/p/06365b31dff1
就不讲怎么进入阿里图标库生成ttf的了,文章中有很多,也比较简单,毕竟是国内的网站
用的时候发现不知道怎么设置图片大小和图片颜色,网上找了一个demo
class FontIconView extends android.support.v7.widget.AppCompatTextView { /* * 控件在xml加载的时候是调用两个参数的构造函数 ,为了自定义的控件的完整性我们可以 * 都把构造函数写出来 */ public FontIconView(Context context) { super(context); init(context); } public FontIconView(Context context, AttributeSet attrs) { super(context, attrs); init(context); } public FontIconView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(context); } /** * 初始化 * @param context */ private void init(Context context) { //设置字体图标 Typeface font = Typeface.createFromAsset(context.getAssets(), "iconfont.ttf"); this.setTypeface(font); }}
<com.feng.temp.FontIconView android:id="@+id/fontView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="80dp" android:text="hello_world" > </com.feng.temp.FontIconView>
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FontIconView fontView= (FontIconView) findViewById(R.id.fontView); fontView.setText(getResources().getString(R.string.icon_1)); fontView.setTextColor(Color.parseColor("#00cacb")); //设置颜色 }}
就是基本的使用了,以后有机会在项目中用一下,明天早上问朋友要下他的那个类,看怎样
阅读全文