android - StyledAttributes from theme not properly loaded -
i added custom attribute textview called font. automatically loads custom font.
example xml:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" > <com.egeniq.widget.textview android:layout_width="match_parent" android:layout_height="44dp" app:font="myriadpro" android:text="@string/login_welcome" /> </relativelayout>
the custom widget following in constructors:
typedarray styledattrs = context.obtainstyledattributes(attrs, r.styleable.textview); string customfont = styledattrs.getstring(font); // snip. error occurs here
the r.styleable.textview declared such:
<?xml version="1.0" encoding="utf-8"?> <resources> <attr name="font" format="string" /> <!-- textview --> <declare-styleable name="textview"> <attr name="font" /> </declare-styleable> </resources>
when defined above works. variable string customfont
set proper name (myriadpro).
when trying auto-apply value trough style customfont string empty.
style declared such:
<?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="theme.bicyclebuddy" parent="android:theme.light.notitlebar"> <item name="android:textviewstyle">@style/widget.textview</item> </style> <!-- override defaults --> <style name="widget.textview" parent="@android:style/widget.textview"> <item name="font">myriadpro</item> </style> </resources>
the theme included in manifest:
<application android:name=".application" android:allowbackup="true" android:hardwareaccelerated="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/theme.bicyclebuddy" > </application>
the <item name="font"></item>
gives no errors. custom widget loaded , hits breakpoint. said above. if used 'customfont' property null after reading it.
screenshots of stack: first (where customfont not null) xml includes app:font=""
property. second, not include property, should loaded style
the reason view element different because these 2 different textviews. exact same propertys. 1 includes app:font=""
, other not. breakpoints hit 1 after other in order expect.
as see, virtually equal. id behind styledattrs same. yet if not explicitly declare font property in xml isn't loaded.
i hope directly sees connection missing. realise rather vague issue.
please note com.egeniq.* custom library attached project. styles.xml declared in 'main project', while attrs.xml library project
Comments
Post a Comment