2015-02-10 86 views
2

如何獲取當前在textview/edittext中使用的字體?我不設置自定義字體,但需要知道哪些字體Android使用,以顯示我的TextView文本:能登的Roboto,諾託CJK或SANSSERIF希伯來語等從textview/edittext獲取字體

+0

getTypeface()將幫助您。 – droidd 2015-02-10 06:07:33

+0

我試過了,收到了null。 – 2015-02-10 06:12:17

回答

0

您是否嘗試過在你的TextView調用getTypeface()你改變之前它並將結果存儲在某個地方? Check this link, this will help you

+0

我試了一下,收到了null。 – 2015-02-10 06:11:15

+0

在您的問題中發佈您的代碼。 – iOSNoob 2015-02-10 06:16:08

+0

我使用了默認的hello world樣本。我通過ID獲取TextView並通過textview調用getTypeface。而已。 – 2015-02-10 06:19:27

1

你的問題沒有錯。 如果您還沒有使用setTypeFace()您將收回null T extViewButton的默認TypeFace在style.xml中定義。 喜歡的東西:

<style name="AppTheme" parent="AppBaseTheme"> 
    <item name="android:textViewStyle">@style/RobotoTextViewStyle</item> 
    <item name="android:buttonStyle">@style/RobotoButtonStyle</item> 
</style> 

<style name="RobotoTextViewStyle" parent="android:Widget.TextView"> 
    <item name="android:fontFamily">sans-serif-light</item> 
</style> 

檢查這個問題Default Font-Family for AppDeafault font

我沒有嘗試過自己,你是正確的,它返回null 好像字體更改默認屬性,但attriburtes至極的觀點開始不直接解釋爲typeFace