如何在自定义的文本添加阴影? [英] How to add shadow on custom text?

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

问题描述

我试着用XML文件和code添加阴影自定义字体没有任何成功

我的code是

  TextView的文字=(TextView的)findViewById(R.id.text1);
字样TF = Typeface.createFromAsset(getAssets(),字体/ gillsans.ttf);
text.setTypeface(TF);
 

解决方案

使用这样的:

Activity.class

  TextView的文字=(TextView的)findViewById(R.id.text1);
    字样TF = Typeface.createFromAsset(getAssets(),字体/ gillsans.ttf);
    text.setTypeface(TF);
////////////

    着色textShader =新的LinearGradient(2,0,4,60,
                    新INT [] {Color.parseColor(#b4e391),Color.parseColor(#61c419),Color.parseColor(#b4e391)},
                    新浮法[] {0,3,1},TileMode.MIRROR);
            text.getPaint()setShader(textShader)。
 

main.xml中:

 <的TextView
            机器人:ID =@ + ID / text1中
            机器人:重力=中心
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
             机器人:shadowDx =5
            机器人:shadowDy =5
            机器人:layout_marginRight =42dp
            机器人:layout_marginTop = -  10dp
            机器人:layout_gravity =右| center_vertical

            机器人:则shadowColor =#67587686

            机器人:shadowRadius =3
            机器人:TEXTSIZE =25dp
            机器人:文本=99%/>
 

i tried with xml file and with code to add shadow to custom font without any success

my code is

TextView text=(TextView)findViewById(R.id.text1);
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/gillsans.ttf");
text.setTypeface(tf);

解决方案

use this:

Activity.class :

    TextView text=(TextView)findViewById(R.id.text1);
    Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/gillsans.ttf");
    text.setTypeface(tf);
////////////

    Shader textShader=new LinearGradient(2, 0, 4, 60,
                    new int[]{Color.parseColor("#b4e391"),Color.parseColor("#61c419"),Color.parseColor("#b4e391")},
                    new float[]{0, 3,1}, TileMode.MIRROR);
            text.getPaint().setShader(textShader);

main.xml:

 <TextView
            android:id="@+id/text1"
            android:gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
             android:shadowDx="5"
            android:shadowDy="5"
            android:layout_marginRight="42dp"
            android:layout_marginTop="-10dp"
            android:layout_gravity="right|center_vertical"

            android:shadowColor="#67587686"

            android:shadowRadius="3"
            android:textSize="25dp"
            android:text="99%" />

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

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