Android中文本的阴影效果?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3297437/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:33:56  来源:igfitidea点击:

Shadow Effect for a Text in Android?

androidtextviewshadow

提问by Praveen

Possible Duplicate:
Android - shadow on text?

可能的重复:
Android - 文字上的阴影?

How can i make shadow effect text in a TextView.

如何在TextView.

Any Idea?

任何的想法?

回答by Codeversed

put these in values/colors.xml

把这些放在 values/colors.xml 中

<resources>
    <color name="light_font">#FBFBFB</color>
    <color name="grey_font">#ff9e9e9e</color>
    <color name="text_shadow">#7F000000</color>
    <color name="text_shadow_white">#FFFFFF</color>
</resources>

Then in your layout xml here are some example TextView's

然后在您的布局 xml 中,这里有一些 TextView 示例

Example of Floating text on Light with Dark shadow

带有暗阴影的浅色浮动文本示例

<TextView android:id="@+id/txt_example1"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:textSize="14sp"
                  android:textStyle="bold"
                  android:textColor="@color/light_font"
                  android:shadowColor="@color/text_shadow"
                  android:shadowDx="1"
                  android:shadowDy="1"
                  android:shadowRadius="2" />

enter image description here

在此处输入图片说明

Example of Etched text on Light with Dark shadow

带有暗阴影的浅色蚀刻文字示例

<TextView android:id="@+id/txt_example2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="14sp"
                android:textStyle="bold"
                android:textColor="@color/light_font"
                android:shadowColor="@color/text_shadow"
                android:shadowDx="-1"
                android:shadowDy="-1"
                android:shadowRadius="1" />

enter image description here

在此处输入图片说明

Example of Crisp text on Light with Dark shadow

明暗暗影清晰文本示例

<TextView android:id="@+id/txt_example3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="14sp"
                android:textStyle="bold"
                android:textColor="@color/grey_font"
                android:shadowColor="@color/text_shadow_white"
                android:shadowDx="-2"
                android:shadowDy="-2"
                android:shadowRadius="1" />

enter image description here

在此处输入图片说明

Notice the positive and negative values... I suggest to play around with the colors/values yourself but ultimately you can adjust these settings to get the effect your looking for.

注意正值和负值...我建议自己使用颜色/值,但最终您可以调整这些设置以获得您想要的效果。

回答by Pontus Gagge

Perhaps you'd consider using android:shadowColor, android:shadowDx, android:shadowDy, android:shadowRadius; alternatively setShadowLayer()?

也许你会考虑使用android:shadowColor, android:shadowDx, android:shadowDy, android:shadowRadius; 或者setShadowLayer()

回答by DanM

TextView textv = (TextView) findViewById(R.id.textview1);
textv.setShadowLayer(1, 0, 0, Color.BLACK);