android - 如何在自定义文本上添加阴影?

标签 android textview dropshadow

我尝试使用 xml 文件和代码为自定义字体添加阴影,但没有成功

我的代码是

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

最佳答案

使用这个:

Activity 类:

    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);

ma​​in.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%" />

关于android - 如何在自定义文本上添加阴影?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9646775/

相关文章:

android - 处理 ACTION_EDIT 结果

android - Espresso,当 NestedScrollView 或 RecyclerView 在 CoordinatorLayout 中时滚动不起作用

android - 某些设备中的 NullPointerException GoogleMaps

android - 在 Text View android 中设置 Span 样式的 HTML 文本

iphone - iOS : Create one sideded dropshadow

shadow - CSS中box-shadow和-moz-box-shadow的具体解释是什么?

swift - 带有角半径和阴影 View 的 UIView 不会在角中剪切 subview

android - 为什么我的简单单一公式 android 计算器应用程序 apk 的大小为 1.5 MB,而其他一些好的应用程序 apk 的大小很小(以 KB 为单位)

android - 将文本设置为整数值

android - 如何在发生意外崩溃时保存 Activity 数据