2015-07-04 69 views
1

我試圖在我的佈局中將monospace字體設置爲列表視圖,但似乎棒棒糖忽略了字體集。棒棒糖下的其他api版本可以很好地顯示我想要的結果。在棒棒糖上忽略字體等寬字體

ps: 我不想設置一個全局字體,我只想爲我的listview的api> 21的等寬字體texttypeface。 任何幫助將是appreciated.Thanks

編輯

<ListView 
android:layout_gravity="start" 
android:id="@+id/List" 
android:tag="toggle" 
android:background="#99111111" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:scrollingCache="false" 
android:typeface="monospace " 
    android:dividerHeight="0.0dip" /> 
+0

「ListView」沒有字體,因爲「ListView」沒有文字。 「ListView」內的行內部的小部件可能有文本。請發佈此問題的[最簡單,完整且可驗證的示例](http://stackoverflow.com/help/mcve)。 – CommonsWare

+0

已編輯我的帖子,添加更多信息。 – CodeZero

+0

在所有版本的Android上都應該忽略該屬性,因爲['ListView'不支持'typeface'](http://developer.android.com/reference/android/widget/ListView.html)。您需要在行中的小部件上設置字體。 – CommonsWare

回答

3

材料文本出場指定android:fontFamily屬性,而不是android:typeface

試試這個全球造型,

<style name="AppTheme" parent="AppBaseTheme"> 
    <item name="android:textViewStyle">@style/MonospaceTextViewStyle</item> 
</style> 

<style name="MonospaceTextViewStyle" parent="android:Widget.TextView"> 
    <item name="android:fontFamily">monospace</item> 
</style> 

現在只需將主題添加到您的活動,

<application 
    android:theme="@style/AppTheme" > 
</application> 

如果你的ListView與自定義適配器創建的,你也可以直接添加屬性在TextView中,

<TextView 
    .....  
    android:fontFamily="monospace"   
    ..... 
    /> 
+0

這使得我的整個應用程序文本繼承不等於期望結果的等寬字體。 – CodeZero

+0

@CodeZero你把這條線放在哪裏? –

+0

添加更多信息 – CodeZero