使用效果

<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_margin="10dp"android:orientation="horizontal"><com.bqt.lizhi.demo.IconFontTextViewandroid:layout_width="40dp"android:layout_height="40dp"android:background="@android:color/holo_blue_bright"android:gravity="center"android:text="@string/ic_live_talk_jockey_microphone_off"android:textColor="#f00"android:textSize="17sp"/><com.bqt.lizhi.demo.IconFontTextViewandroid:layout_width="40dp"android:layout_height="40dp"android:layout_marginLeft="10dp"android:gravity="center"android:text="@string/ic_record_audition"android:textColor="#0f0"android:textSize="17sp"app:if_fillColor="#3f00"/><com.bqt.lizhi.demo.IconFontTextViewandroid:layout_width="40dp"android:layout_height="40dp"android:layout_marginLeft="10dp"android:background="@android:color/holo_blue_bright"android:gravity="center"android:text="@string/ic_live_ent_mode"android:textColor="#00f"android:textSize="17sp"app:if_fillColor="#3f00"/><com.bqt.lizhi.demo.IconFontTextViewandroid:layout_width="40dp"android:layout_height="40dp"android:layout_marginLeft="10dp"android:gravity="center"android:text="@string/ic_live_talk_loudspeaker"android:textColor="#000"android:textSize="17sp"app:if_strokeColor="#0f0"app:if_strokeWidth="2dp"/>
</LinearLayout>
51
1
<?xml version="1.0" encoding="utf-8"?>

2
<LinearLayout

3
    xmlns:android="http://schemas.android.com/apk/res/android"

4
    xmlns:app="http://schemas.android.com/apk/res-auto"

5
    android:layout_width="match_parent"

6
    android:layout_height="match_parent"

7
    android:layout_margin="10dp"

8
    android:orientation="horizontal">

9
10
    <com.bqt.lizhi.demo.IconFontTextView

11
        android:layout_width="40dp"

12
        android:layout_height="40dp"

13
        android:background="@android:color/holo_blue_bright"

14
        android:gravity="center"

15
        android:text="@string/ic_live_talk_jockey_microphone_off"

16
        android:textColor="#f00"

17
        android:textSize="17sp"/>

18
19
    <com.bqt.lizhi.demo.IconFontTextView

20
        android:layout_width="40dp"

21
        android:layout_height="40dp"

22
        android:layout_marginLeft="10dp"

23
        android:gravity="center"

24
        android:text="@string/ic_record_audition"

25
        android:textColor="#0f0"

26
        android:textSize="17sp"

27
        app:if_fillColor="#3f00"/>

28
29
    <com.bqt.lizhi.demo.IconFontTextView

30
        android:layout_width="40dp"

31
        android:layout_height="40dp"

32
        android:layout_marginLeft="10dp"

33
        android:background="@android:color/holo_blue_bright"

34
        android:gravity="center"

35
        android:text="@string/ic_live_ent_mode"

36
        android:textColor="#00f"

37
        android:textSize="17sp"

38
        app:if_fillColor="#3f00"/>

39
40
    <com.bqt.lizhi.demo.IconFontTextView

41
        android:layout_width="40dp"

42
        android:layout_height="40dp"

43
        android:layout_marginLeft="10dp"

44
        android:gravity="center"

45
        android:text="@string/ic_live_talk_loudspeaker"

46
        android:textColor="#000"

47
        android:textSize="17sp"

48
        app:if_strokeColor="#0f0"

49
        app:if_strokeWidth="2dp"/>

50
</LinearLayout>

51

控件 IconFontTextView

public class IconFontTextView extends android.support.v7.widget.AppCompatTextView {private Paint paint;private int strokeWidth;private int strokeColor;private int fillColor;private boolean enablePressEffect = true; // 按下半透明效果public IconFontTextView(Context context) {this(context, null);}public IconFontTextView(Context context, AttributeSet attrs) {this(context, attrs, 0);}public IconFontTextView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);this.setTypeface(IconFontUtil.getIconfont(context));TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.IconFontTextView, defStyleAttr, 0);strokeColor = a.getColor(R.styleable.IconFontTextView_if_strokeColor, 0);strokeWidth = a.getDimensionPixelSize(R.styleable.IconFontTextView_if_strokeWidth, 0);fillColor = a.getColor(R.styleable.IconFontTextView_if_fillColor, 0);enablePressEffect = a.getBoolean(R.styleable.IconFontTextView_if_enablePressEffect, true);a.recycle();paint = new Paint();paint.setAntiAlias(true);}public void setStrokeColor(@ColorInt int strokeColor) {this.strokeColor = strokeColor;invalidate();}@Overridepublic void setPressed(boolean pressed) {super.setPressed(pressed);if (!isEnabled()) {return;}if (enablePressEffect) {if (pressed) {setAlpha(0.5F);} else {setAlpha(1);}}}@Overridepublic void setEnabled(boolean enabled) {super.setEnabled(enabled);if (enabled) {setAlpha(1);} else {setAlpha(0.2F);}}@Overrideprotected void onDraw(Canvas canvas) {int center = getWidth() / 2;if (strokeColor != 0) {if (strokeWidth != 0) {this.paint.setStyle(Paint.Style.STROKE);this.paint.setStrokeWidth(strokeWidth);}this.paint.setColor(strokeColor);if (strokeWidth != -1) {canvas.drawCircle(center, center, getWidth() / 2 - strokeWidth / 2, this.paint);} else {canvas.drawCircle(center, center, getWidth() / 2, this.paint);}}if (fillColor != 0) {this.paint.setStyle(Paint.Style.FILL);this.paint.setColor(fillColor);canvas.drawCircle(center, center, getWidth() / 2, this.paint);}super.onDraw(canvas);}
}
x

1
public class IconFontTextView extends android.support.v7.widget.AppCompatTextView {

2
    

3
    private Paint paint;

4
    private int strokeWidth;

5
    private int strokeColor;

6
    private int fillColor;

7
    private boolean enablePressEffect = true; // 按下半透明效果

8
    

9
    public IconFontTextView(Context context) {

10
        this(context, null);

11
    }

12
    

13
    public IconFontTextView(Context context, AttributeSet attrs) {

14
        this(context, attrs, 0);

15
    }

16
    

17
    public IconFontTextView(Context context, AttributeSet attrs, int defStyleAttr) {

18
        super(context, attrs, defStyleAttr);

19
        

20
        this.setTypeface(IconFontUtil.getIconfont(context));

21
        

22
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.IconFontTextView, defStyleAttr, 0);

23
        strokeColor = a.getColor(R.styleable.IconFontTextView_if_strokeColor, 0);

24
        strokeWidth = a.getDimensionPixelSize(R.styleable.IconFontTextView_if_strokeWidth, 0);

25
        fillColor = a.getColor(R.styleable.IconFontTextView_if_fillColor, 0);

26
        enablePressEffect = a.getBoolean(R.styleable.IconFontTextView_if_enablePressEffect, true);

27
        a.recycle();

28
        

29
        paint = new Paint();

30
        paint.setAntiAlias(true);

31
    }

32
    

33
    public void setStrokeColor(@ColorInt int strokeColor) {

34
        this.strokeColor = strokeColor;

35
        invalidate();

36
    }

37
    

38
    @Override

39
    public void setPressed(boolean pressed) {

40
        super.setPressed(pressed);

41
        if (!isEnabled()) {

42
            return;

43
        }

44
        

45
        if (enablePressEffect) {

46
            if (pressed) {

47
                setAlpha(0.5F);

48
            } else {

49
                setAlpha(1);

50
            }

51
        }

52
    }

53
    

54
    @Override

55
    public void setEnabled(boolean enabled) {

56
        super.setEnabled(enabled);

57
        if (enabled) {

58
            setAlpha(1);

59
        } else {

60
            setAlpha(0.2F);

61
        }

62
    }

63
    

64
    @Override

65
    protected void onDraw(Canvas canvas) {

66
        

67
        int center = getWidth() / 2;

68
        if (strokeColor != 0) {

69
            

70
            if (strokeWidth != 0) {

71
                this.paint.setStyle(Paint.Style.STROKE);

72
                this.paint.setStrokeWidth(strokeWidth);

73
            }

74
            

75
            this.paint.setColor(strokeColor);

76
            

77
            if (strokeWidth != -1) {

78
                canvas.drawCircle(center, center, getWidth() / 2 - strokeWidth / 2, this.paint);

79
            } else {

80
                canvas.drawCircle(center, center, getWidth() / 2, this.paint);

81
            }

82
        }

83
        

84
        if (fillColor != 0) {

85
            this.paint.setStyle(Paint.Style.FILL);

86
            this.paint.setColor(fillColor);

87
            canvas.drawCircle(center, center, getWidth() / 2, this.paint);

88
        }

89
        

90
        super.onDraw(canvas);

91
    }

92
}

93

获取字体 IconFontUtil

public class IconFontUtil {private static Typeface mIconfont;public static Typeface getIconfont(Context context) {if (mIconfont == null) {mIconfont = Typeface.createFromAsset(context.getAssets(), "iconfont/lizhifm.ttf");}return mIconfont;}
}
iconfont
x

1
public class IconFontUtil {

2
    private static Typeface mIconfont;

3
    

4
    public static Typeface getIconfont(Context context) {

5
        if (mIconfont == null) {

6
            mIconfont = Typeface.createFromAsset(context.getAssets(), "iconfont/lizhifm.ttf");

7
        }

8
        return mIconfont;

9
    }

10
}

自定义属性 attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources><declare-styleable name="IconFontTextView"><attr name="if_strokeWidth" format="dimension"/><attr name="if_strokeColor" format="color"/><attr name="if_fillColor" format="color"/><attr name="if_enablePressEffect" format="boolean"/></declare-styleable>
</resources>
x

1
<?xml version="1.0" encoding="utf-8"?>

2
<resources>

3
    <declare-styleable name="IconFontTextView">

4
        <attr name="if_strokeWidth" format="dimension"/>

5
        <attr name="if_strokeColor" format="color"/>

6
        <attr name="if_fillColor" format="color"/>

7
        <attr name="if_enablePressEffect" format="boolean"/>

8
    </declare-styleable>

9
</resources>

字体效果

荔枝FM字体效果
微软雅黑
宋体
Arial
2018-1-3

附件列表

荔枝FM 字体文件 IconFontTextView相关推荐

  1. [c#]喜马拉雅、蜻蜓、荔枝FM音频批量下载器V1.3 by Levme开发手记

    0.前言 好久没在CSDN上写东西了,看了之前开发的下载器由于三个网站代码更新已经不能用了,应要求,重分析了三个网站播放机制,写了1.3版本的下载器,在我的资源里有下载. 贴个地址:https://d ...

  2. 面试06,[长亮科技]()(offer)、[荔枝]()FM(在确定部门和薪资)、[涂鸦智能]()(第一轮电话面半小时,待后续)、华资软件(HR面)、[广州速游]()(已挂)。至于公司怎么样不加以言论。

    作者:Carson-Zhao 链接:https://ac.nowcoder.com/discuss/522002?type=2&order=0&pos=16&page=1&am ...

  3. fm计算机,荔枝FM电脑版

    荔枝FM电脑版官方版是一款因为热爱而生的音乐产品,专注于发现和分享优质音乐内容,其创新领先的录音功能开启"人人都是主播"的时代.独具匠心的设计.多样化的内容.个性化的体验,用心为用 ...

  4. 直播用什么声音测试软件,荔枝FM直播助手测试方法,请看图文说明

    荔枝FM直播助手,这款专门为主播们打造的辅助工具,相信很多资深的直播玩家都对它非常熟悉.可是,对于很多新手主播来说,在利用它时,却发现自己无法正确驾驭它.那么,荔枝FM直播助手怎么用才能为自己的听众们 ...

  5. 荔枝FM架构师刘耀华:异地多活IDC机房架构

    声明:本文首发于CSDN,禁止未经许可的任何形式转载,可咨询文末的责编. 多机房架构存在的原因 单机房一旦死机,断电.维护根本无法挽回整个数据,想离线读取等都不行.当一个机房不可用,所有的业务就都不可 ...

  6. 荔枝fm电脑版 v1.5.2 官方版

    荔枝fm电脑版 v1.5.2 官方版 软件大小:9.4MB 软件语言:简体中文 软件类别:影音其他 软件授权:官方版 应用平台:/Win8/Win7/WinXP 是一款基于模拟器的音乐电台.荔枝fm电 ...

  7. 荔枝FM:异地多活IDC机房架构

    http://geek.csdn.net/news/detail/53231 多机房架构存在的原因 单机房一旦死机,断电.维护根本无法挽回整个数据,想离线读取等都不行.当一个机房不可用,所有的业务就都 ...

  8. 通过上传ttf或者otf字体文件生成对应字体的图片

    由于项目需求,需要通过上传的字体文件来生成对应的图片以方便用户快速查看字体效果,经查阅信息后完成此需求,记录下此以供日后学习巩固.根据思路,首先是获取到字体文件的url,然后根据url获取到字体文件, ...

  9. apache字体文件跨域_apache如何解决跨域资源访问

    很多时候,大中型网站为了静态资源分布式部署,加快访问速度,减轻主站压力,会把静态资源(例如字体文件.图片等)放在独立服务器或者CDN上,并且使用独立的资源域名(例如res.test.com) 但是在实 ...

最新文章

  1. 判断两个数组内容是否相同
  2. 测试core :: demangled_name
  3. DSPack的Demo中,那个VMR目录是什么意思?
  4. linux 多个会话同时执行命令后history记录不全的解决方案
  5. anaconda来创建python环境
  6. RuntimeError: Expected object of device type cuda but got device type cpu for argument #2 'target'
  7. 海龟交易法则10_通用积木
  8. 安装了IE8.0之后网页按钮变小的恢复
  9. SVN 代码与文件管理小记
  10. docker tensorflow_用Docker容器方式安装TensorFlow
  11. 转并学习: 将rar文件转换为zip格式
  12. [R]_R里如何将多个Excel文件合并为一个Excel文件多个Sheet
  13. ZBrush如何结合数位板雕刻模型
  14. winrar捆绑软件
  15. 移动硬盘格式化了的数据找回方法
  16. 【推荐】超级好用的打印插件Lodop使用笔记 动态赋值 打印模板解决方案
  17. 岁月的感知,生命的守望
  18. 如何监控Redis性能指标
  19. python课程设计----简单爬虫
  20. 鸿蒙系统浏览器内核,四大浏览器横评出炉:Chromium 内核版 Edge 四项夺冠,优于原生 Chrome...

热门文章

  1. BZOJ 2947 Poi2000 促销 set
  2. Java总结篇系列:Java多线程(二)
  3. android主流开源自动化框架(monkeyrunner,robotium,uiautomator
  4. 转载 - 使用HTML5、CSS3和jQuery增强网站用户体验
  5. 我在51cto微职位学软考——宝妈一次性通过高项的学习经历
  6. Redis 4.0.X版本reshard出现错误的解决办法
  7. NSURLConnection实现文件上传和AFNetworking实现文件上传
  8. Scrumban-拉动企业渐进式变革的利器
  9. 最初的感动:各种应用和代码在BCH这里不断复活
  10. iOS swift2.3 迁移到3.0 遇到的一些问题