如何在文本上添加描边 [英] how to add stroke on text

查看:30
本文介绍了如何在文本上添加描边的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到在文本上描边的方法(在文本上,而不是在整个文本视图框上),描边应该在字母周围.是否有任何自定义文本视图或库或绘图可以实现绘制笔画

 

我希望文本看起来像这样,(笔触颜色为红色)

解决方案

我尝试了以下两种向文本添加笔划的方法:

首先是给你的 TextView 添加阴影:

以上代码的输出为:

第二次我找到了 GitHub 项目 android-outline-textview.

希望对你有用.

I can't find a way to put a stroke on text (on the text, not on the whole text view box) , the stroke should be around the letters. is there any custom text view or library or drawing can be implemented to draw a stroke

        <TextView
            style="@style/Header"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="150dp"
            android:text="HELLO DROID"
            />

i expect the text to look like so , (the stroke color is red)

解决方案

I tried below two ways for adding stroke to text :

First is add shadow to your TextView:

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="50sp"
        android:textColor="@android:color/holo_blue_light"
        android:text="Hello"
        android:shadowRadius="10"
        android:shadowDx="1"
        android:shadowDy="1"
        android:shadowColor="@android:color/holo_red_dark"/>

The output of above code is:

Second I found GitHub project android-outline-textview. Please follow this Link

For this you need to add StrokedTextView and related files to your project after that add below Code in XML file:

 <com.skd.stackdemo.StrokedTextView
        android:id="@+id/stroke"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="60sp"
        android:text="Hello"
        android:textColor="@android:color/holo_blue_light"
        android:layout_marginTop="30dp"/>

Add below code in Java file:

StrokedTextView stroke = findViewById(R.id.stroke);
stroke.setStrokeColor(Color.RED);
stroke.setStrokeWidth(1f);

The output of above code is:

I hope it works for you.

这篇关于如何在文本上添加描边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆