代码之家  ›  专栏  ›  技术社区  ›  Praveen

Android中文本的阴影效果?[复制品]

  •  183
  • Praveen  · 技术社区  · 14 年前

    可能重复:
    Android - shadow on text?

    如何使阴影效果文本 TextView .

    有什么想法吗?

    3 回复  |  直到 8 年前
        1
  •  189
  •   WarrenFaith    13 年前

    也许你会考虑使用 android:shadowColor , android:shadowDx , android:shadowDy , android:shadowRadius 可替代地 setShadowLayer() ?

        2
  •  344
  •   Jonathan Argentiero Aadish Goel    8 年前

    把它们放在values/colors.xml中

    资源 <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> < /代码>

    然后在布局XML中,这里是一些textview的示例

    带深色阴影的灯光上浮动文本的示例

    <textView android:id=“@+id/txt示例1”
    android:layout_width=“包装内容”
    android:layout_height=“包装内容”
    安卓:textsize=“14sp”
    android:textstyle=“粗体”
    android:textcolor=“@color/light\u字体”
    android:shadow color=“@color/text\u阴影”
    安卓:shadowdx=“1”
    安卓:shadowdy=“1”
    android:shadowRadius=“2”/>
    < /代码> 
    
    

    带深色阴影的光上蚀刻文本示例

    <textView android:id=“@+id/txt示例2”
    android:layout_width=“包装内容”
    android:layout_height=“包装内容”
    安卓:textsize=“14sp”
    android:textstyle=“粗体”
    android:textcolor=“@color/light\u字体”
    android:shadow color=“@color/text\u阴影”
    android:shadowdx=“-1”
    android:shadowdy=“-1”
    android:shadowRadius=“1”/>
    < /代码> 
    
    

    明暗阴影下清晰文本示例

    <textView android:id=“@+id/txt示例3”
    android:layout_width=“包装内容”
    android:layout_height=“包装内容”
    安卓:textsize=“14sp”
    android:textstyle=“粗体”
    android:textcolor=“@color/grey_字体”
    android:shadow color=“@color/text\u shadow\u白色”
    android:shadowdx=“-2”
    android:shadowdy=“-2”
    android:shadowRadius=“1”/>
    < /代码> 
    
    

    注意正负值…我建议你自己玩弄颜色/值,但最终你可以调整这些设置来获得你想要的效果。

    然后在布局XML中,这里是一些textview的示例

    带深色阴影的光上浮动文本示例

    <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

    带深色阴影的光上蚀刻文本示例

    <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

    明暗阴影下清晰文本示例

    <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

    注意正负值…我建议你自己玩弄颜色/值,但最终你可以调整这些设置来获得你想要的效果。

        3
  •  60
  •   DanM    13 年前
    TextView textv = (TextView) findViewById(R.id.textview1);
    textv.setShadowLayer(1, 0, 0, Color.BLACK);