Android 给字体苗边

之前写过一篇关于字体苗边的文章:

Android 引入自体库 改变字体样式(给字体描边),但是效果不好。

现在介绍一种新的方法。

基本思路和之前一样,都是两个TextView叠在一起,两者字体大小一样,

而下面的字体粗一些。之前是直接设置的粗体,现在通过改变画笔的粗细
来实现,效果好多了,先看效果:
代码很简单:
layout布局文件:

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

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

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

android:textSize="50sp"

android:textColor="#42979f"

android:id="@+id/tvBack"

android:shadowColor="#42979f"

android:shadowDx="2"

android:shadowDy="2"

android:shadowRadius="5"

/>

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

android:textSize="50sp"

android:textColor="#ffffff"

/>

</RelativeLayout>

.java文件

Paint paint = ((TextView) findViewById(R.id.tvBack)).getPaint();

paint.setStyle(Paint.Style.STROKE);

paint.setStrokeWidth(8);

需要注意的是,paint.setStrokeWidth()起作用的前提是paint.setStyle(Paint.Style.STROKE);(字体空心),另外为了使字体

看起来更立体,我加了阴影效果:

android:shadowColor="#42979f"

android:shadowDx="2"

android:shadowDy="2"

android:shadowRadius="5"

此条目发表在 Android开发 分类目录,贴了 , , , , , , , , , , , 标签。将 固定链接加入收藏夹。

Android 给字体苗边》有 1 条评论

  1. Pingback 引用通告: 自定义控件 –百科专家总结 | 易网联信

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值