2012-01-22 62 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