2012-04-16 18 views
5

पर कस्टम फोंट कैसे जोड़ें मुझे पता है कि कस्टम फ़ॉन्ट को टेक्स्ट व्यू में कैसे सेट करें। लेकिन थीम/शैली/एक्सएमएल के माध्यम से कस्टम फ़ॉन्ट कैसे जोड़ें ??एंड्रॉइड: विषय/शैली/एक्सएमएल

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="customfontforlistview" parent="@android:style/Widget.ListView"> 
     <item name="android:textColor">#000000</item> 
     <item name="android:typeface">HOW_TO_CUSTOM_FONT</item> 
    </style> 
</resources> 

कृपया इसके लिए समाधान प्रदान करें।

उत्तर

3

जहां तक ​​मुझे पता है कि ऐसा करने का कोई अच्छा तरीका नहीं है।

public class CustomTextViewNormal extends TextView 
{ 
    public CustomTextViewNormal(Context context) 
    { 
     super(context); 
     init(); 
    } 

    public CustomTextViewNormal(Context context, AttributeSet attrs) 
    { 
     super(context, attrs); 
     init(); 
    } 

    public CustomTextViewNormal(Context context, AttributeSet attrs, int defStyle) 
    { 
     super(context, attrs, defStyle); 
     init(); 
    } 

    public void init() 
    { 
     Typeface tf = Typeface.createFromAsset(getContext().getAssets(), 
       "fonts/HelveticaNeue.ttf"); 
     setTypeface(tf); 
    } 
} 

आप इस करते हैं, तो आप सिर्फ इस कस्टम पाठ दृश्य का उपयोग कर सकते हैं एक्सएमएल लेआउट में और आप मूलतः एक ही कार्यक्षमता के रूप में है: सबसे अच्छा विकल्प है कि मैं जानता हूँ कि एक साधारण उपवर्ग है कि कुछ इस तरह दिखता बनाने के लिए है एक शैली हालांकि, स्वीकार्य रूप से, थोड़ा ढलान।

+0

यह एक डाउनवोट नहीं है! सही उत्तर। कम से कम एक तरीका यह कैसे करें – longilong

+0

एंड्रॉइड: textStyle = "bold" इस विरासत वाले टेक्स्टव्यू पर काम नहीं कर रहा है :( –