How to get fontFamily name from TextView?

I want to get the first name attr surname font from xml in code. For example, I have my own textView class:

public class TextVieww extends TextView{

    public TextVieww(Context context) {
        super(context);
    }
    public TextVieww(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public TextVieww(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    public void init(Context mContext ,TextView view) {
    }
}

XML:

 <com.typefacetest.TextVieww
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="30sp"
        android:textStyle="bold"
        android:fontFamily="sans-serif-thin"
        android:text="Hello World!" />

I want to get "sans-serif-thin" from textView.class. Is it possible? and how to do it? thank you's

+4
source share
2 answers

, XML, , XML, - ( , Typeface ).

@Ashwini, "" XML, .java.

, , - ; android: TextView :

XML:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    android:id='@+id/textView'
    android:textSize="30sp"
    android:textStyle="bold"
    android:fontFamily="@string/myFontFamily"
    android:tag="@string/myFontFamily"
/>

res/values ​​/strings.xml:

<resources>
    ...
    <string name="myFontFamily">sans-serif-thin</string>
    ...
</resources>

android: tag:

TextView textView = (TextView) findViewById(R.id.textView);
String fontFamily = String.valueOf(textView.getTag());
+2

http://developer.android.com/reference/android/widget/TextView.html#getTypeface()

- setTypeface(Typeface.SANS_SERIF) TextView

public Typeface getTypeface ()

:

, .

+2

All Articles