Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is the way to change the font typeface using xml.</p> <ol> <li><p>Define a new NameSpace: <code>xmlns:your_namespace="http://schemas.android.com/apk/res/com.nound.test"</code> (“com.nound.test” is the package name defined in Manifest.xml)</p></li> <li><p>Define the custom attribute(s) in /res/values/attrs.xml file.</p> <pre><code>&lt;resources&gt; &lt;declare-styleable name="TypefacedTextView"&gt; &lt;attr name="textStyle" format="string"/&gt; &lt;/declare-styleable&gt; &lt;/resources&gt; </code></pre></li> <li><p>Java class that extends TextView... as follows public class TypefacedTextView extends TextView {</p> <pre><code>public TypefacedTextView(Context context, AttributeSet attrs) { super(context, attrs); //Typeface.createFromAsset doesn't work in the layout editor. Skipping... if (isInEditMode()) { return; } TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.TypefacedTextView); //String fontName = styledAttrs.getString(R.styleable.TypefacedTextView_typeface); String fontNameForBold = styledAttrs.getString(R.styleable.TypefacedTextView_textStyle); styledAttrs.recycle(); if (fontNameForBold!=null &amp;&amp; fontNameForBold.equals("bold")) { Typeface typeface_bold = Typeface.createFromAsset(context.getAssets(), "fonts/tahoma/tahoma_bold.ttf"); setTypeface(typeface_bold); }else{ Typeface typeface = Typeface.createFromAsset(context.getAssets(), "fonts/tahoma/tahoma.ttf"); setTypeface(typeface); } } </code></pre></li> <li><p>here is the layout code where you wanna change the font typeface. in this "com.nound.test.ui" is the above (3 point) java file package name. TypefacedTextView is class name.</p></li> </ol> <blockquote> <pre><code>&lt;com.nound.test.ui.TypefacedTextView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:your_namespace="http://schemas.android.com/apk/res/com.nound.test" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Custom fonts in XML are easy_bold font" your_namespace:textStyle="bold" /&gt; &lt;com.nound.test.ui.TypefacedTextView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:your_namespace="http://schemas.android.com/apk/res/com.nound.test" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Custom fonts in XML are easy_regular font" /&gt; </code></pre> </blockquote> <p>its enough to do...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload