2012-01-22 61 views

回答

4

Android本来没有这样的功能。几个月前,我不得不开发一个类似的功能,我用了一些技巧。在这种情况下,我使用了shadow属性。在你的情况TextView.onDraw()拨打super()两次。将字体设置为粗体,将颜色设置为边框颜色并调用一次,然后设置普通和第二次调用。那可行。

+1

** Android不具备这样的功能本来**。你确定吗?我认为你的过程很长。 –

+0

@CapDroid你的解决方案看起来不错,我的回答太旧:) – lulumeya

12

您可以为此创建样式..

这里是sample style对文本边缘..

Style.xml

<resources xmlns:android="http://schemas.android.com/apk/res/android"> 
<style name="shadoweffect"> 
     <item name="android:paddingLeft">4px</item> 
     <item name="android:paddingBottom">4px</item> 
     <item name="android:textColor">#FFFFFF</item> 
     <item name="android:textSize">25sp</item> 
     <item name="android:shadowColor">#000000</item> 
     <item name="android:shadowDx">0</item> 
     <item name="android:shadowDy">0</item> 
     <item name="android:shadowRadius">3</item> 
    </style> 

</resources> 

在你的TextView将样式

<TextView 
     style="@style/shadoweffect" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="your_text" /> 
+0

感谢@Niranj Patel它在android 7中的工作也 –

0

您可以使用任何TextEd itors创建边境UR文本,您可以添加到代码

+0

我认为OP是通过在XML中设置值寻找一个解决方案? – Flexicoder

20

试试这个..

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello_world" 
    android:textColor="#f8f36a" 
    android:textSize="65sp" 
    android:shadowColor="#ff0000" 
    android:shadowRadius="2"/> 

,其结果是

result

您可以创建自定义文本边框像这样.. Here is a sample application

enter image description here

+0

我在我的项目中使用了MagicTextView。在Android 4.4(API 19)中,我遇到了一个问题:我的应用程序在C库的某处崩溃。它只发生在Android 4.4中。如果我使用TextView而不是MagicTextView,我的应用程序运行良好。 – ivan