android - Accessing custom attribute defined in a style -


The problem I am trying to solve is to put a custom font in the Android application. I have followed some tutorials and stack overflow questions but I really can not seem to get the same.

I have a custom attribute defined in attrs.xml:

  & lt; Resources & gt; & Lt; Declared-style correct name = "custom textview" & gt; & Lt; attr name = "customTypeface" format = "string" /> & Lt; / Declared - Styleable & gt;   

And that custom style is defined in style:

  & lt; Style name = "posTheme" parent = "@ android: genre / Theme.Holo.Light" & gt; & Lt; Item name = "android: textViewStyle" gt; @ style / posThemeTextViewStyle & lt; / Item & gt; & Lt; / Style & gt; & Lt; Style name = "posThemeTextViewStyle" origin = "android: Widget.TextView" & gt; & Lt; Item name = "Android: text size" & gt; 50sp & lt; / Item & gt; & Lt; Item name = "custom typeface" & gt; Fonts / MuseoSans_100.otf & lt; / Item & gt; & Lt; / Style & gt;   

The form appears in any activity:

    

And when I am trying to get the attribute:

  Public Custom Textview (Reference Reference, IAttributeSet attrs, int defStyle): Support , Attrs, defStyle) {var a = context.ObtainStyledAttributes (attrs, Resource.Styleable.CustomTextView); Var customfont = a.getString (resource .style.customestvews_helpteapfaces); SetCustomFont (customFont); A.Recycle (); }   

customFont is zero, unless I define custom: customTypeface = "activity" but I do not want to define the font for every instance of the control. / P>

What am I missing?

Those two lines should not be:

  var a = Context.ObtainStyledAttributes (attrs, Resource.Styleable.CustomTextView); Var customfont = a.getString (resource .style.customestvews_helpteapfaces);   

be:

  var a = context.ObtainStyledAttributes (attrs, R.Styleable.CustomTextView); Var customfont = a.getstring (r. Stylish .custattextoubus_cellTypeface);    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -