Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set custom (arial )type face via xml not via a java code
    primarykey
    data
    text
    <p>I already aware of this:- Typeface typefaceArial= Typeface.createFromAsset(context.getAssets(), "arial.ttf");</p> <p>but when I create the following class it works but it gives <strong>low memory warning</strong> issue.</p> <p>public class MidColorTextView extends TextView {</p> <pre><code>private CharSequence text; private String token; private static Context context; private String colorSpan; private int colorCode; private static Typeface typefaceArial; public MidColorTextView( Context context , AttributeSet attrs ) { super(context, attrs); this.context=null; this.context = context; for(int i = 0; i &lt; attrs.getAttributeCount(); i ++ ) { // Log.i(TAG, attrs.getAttributeName(i)); /* * Read value of custom attributes */ this.text = attrs.getAttributeValue("http://schemas.android.com/apk/res/com.lht", "text"); this.token = attrs.getAttributeValue("http://schemas.android.com/apk/res/com.lht", "token"); this.colorSpan = attrs.getAttributeValue("http://schemas.android.com/apk/res/com.lht", "colorSpan"); // Log.i("TAG", "token " + token); // Log.i("TAG", "text " + text); // Log.i("TAG", "colorSpan " + colorSpan); } init(); } private void init () { if(text.charAt(0) == '@') { String tempText = (String) text.subSequence(1, text.length()); this.text = Html.fromHtml(getResources().getString(Integer.parseInt(tempText))); } if(token.charAt(0) == '@') { String tempText = (String) token.subSequence(1, token.length()); this.token = getResources().getString(Integer.parseInt(tempText)); } if(colorSpan.charAt(0) == '@') { String tempText = (String) colorSpan.subSequence(1, colorSpan.length()); this.colorSpan = getResources().getString(Integer.parseInt(tempText)); } setColorCode(Color.parseColor(colorSpan)); CharSequence textWitoutToken = null; String tempString = text.toString(); // ---------checking whether text containg token or not. if(tempString.contains(token)) { textWitoutToken = setSpanBetweenTokens(text, token, new ForegroundColorSpan(colorCode)); } else { textWitoutToken = text; } textContent = null; setText(textWitoutToken); setTypefaceArial (); setTypeface(getTypefaceArial ()); } public int getColorCode () { return colorCode; } public void setColorCode ( int colorCode ) { this.colorCode = colorCode; } private CharSequence textContent; public static Typeface getTypefaceArial () { return typefaceArial; } public static void setTypefaceArial () { MidColorTextView.typefaceArial= Typeface.createFromAsset(context.getAssets(), "arial.ttf"); } </code></pre> <p>}</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.
 

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