csh_34 2012-10-10 08:25 采纳率: 0%
浏览 4457
已采纳

Android中给自定义文本添加阴影效果

我用xml文件和代码给自定义字体添加阴影,但没有成功,是代码出错吗?

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

2条回答

  • clcurie_11 2012-10-10 09:17
    关注

    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%" />
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器