आप इसे ऐसा कर सकते हैं। एक कस्टम TextView कि एक हर जगह
public class MyTextView extends android.widget.TextView
{
public MyTextView(Context context)
{
this(context, null);
}
public MyTextView(Context context, AttributeSet attrs)
{
this(context, attrs, 0);
}
public MyTextView(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs);
if (this.isInEditMode()) return ;
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SomeStyle);
final String customFont = a.getString(R.styleable.SomeStyle_font);
//Build a custom typeface-cache here!
this.setTypeface(
Typeface.createFromAsset(context.getAssets(), customFont)
);
}
}
जोड़े इस
<declare-styleable name="SomeStyle">
<attr name="font" format="string" />
</declare-styleable>
फिर attrs.xml करने के लिए अपने विषय में बना सकते हैं और उपयोग करते हैं, ऐसा करते हैं: यह सुनिश्चित करें कि सभी textviews शैली का उपयोग करेगा कर देगा MyTextView
<item name="android:textViewStyle">@style/MyTextView</item>
और अब हम इस शैली में आपकी कस्टम विशेषता का उपयोग करके अपने कस्टम फ़ॉन्ट को परिभाषित कर सकते हैं।
<style name="MyTextView" parent="@android:style/Widget.TextView">
<item name="font">MyPathToFontInAssets.ttf</item>
</style>
तो जब भी आप प्रोजेक्ट में MyTextView का उपयोग करते हैं, तो इसका आपका कस्टम फ़ॉन्ट होगा।
महत्वपूर्ण: टाइपफेस कैश नहीं कर रहे हैं, इसलिए यदि आप इस कोड का उपयोग करने की योजना है, तो आप भी एक कस्टम टाइपफेस-कैश ताकि आप सभी textviews के लिए कस्टम टाइपफेस फिर से उपयोग कर सकते हैं का निर्माण करना चाहिए। इससे आवेदन में काफी तेजी आएगी!
अद्यतन: आमिर कह रहे थे के रूप में, यह लगभग Custom fonts and XML layouts (Android) रूप में ही है, लेकिन मैं भी अपने आप ऐप की पूरी textviews पर इसका इस्तेमाल करने एंड्रॉयड स्टाइल का उपयोग करें।
सिर्फ इसलिए कि यह डुप्लिकेट चिह्नित है, कोई बेहतर जवाब प्रदान नहीं कर सकता: इसे प्राप्त करने के लिए सुलेख लाइब्रेरी का उपयोग करें। यह टोस्ट्स के फ़ॉन्ट को भी बदलता है। – suku
इस टट की जांच करें http://www.gadgetsaint.com/android/custom-fonts-textview-edittext-android/#.WNive2996Hs – ASP
क्या आप अभी https://github.com/chrisjenx/Calligraphy – Fattie