android - How can you locate the default style for a widget (i.e. AppCompatEditText) -
update: pointed out in comments, 'widget.appcompat.edittext' correct parent style appcompatedittext subclass. in case, real issue had forgotten assign value our control's default style attribute in our theme, our control wasn't getting style use default.
however, question still use answer how 1 identifies style use parent when defining own default styles when subclassing standard controls. such, i've renamed title.
as such, i'm leaving open in hopes can answer question since wish similar.
we're trying define common look-and-feel appcompatedittext controls used throughout app. such, rather having manually apply 'style' attribute on each usage, we're instead trying replace default style our own.
replacing default style easy part. isn't knowing parent style our style should set still have aspects of original style haven't explicitly overwritten in ours.
digging in source code appcompatedittext, shows default style stored in r.attr.edittextstyle i'm not sure see value stored in it.
experimenting didn't anywhere. no matter have tried far, lose default appearance completely. no underline, no background, no padding, nothing. values we've set, means it's not picking parent style.
we've tried following without success...
<style name="zinedittext" parent="android:widget.edittext"> <item name="zintypeface">light</item> <item name="android:textsize">@dimen/defaulttextsize</item> <item name="android:linespacingmultiplier">@dimen/defaultlinespacing</item> </style> <style name="zinedittext" parent="widget.appcompat.edittext"> <item name="zintypeface">light</item> <item name="android:textsize">@dimen/defaulttextsize</item> <item name="android:linespacingmultiplier">@dimen/defaultlinespacing</item> </style> <style name="zinedittext" parent="base.v7.widget.appcompat.edittext"> <item name="zintypeface">light</item> <item name="android:textsize">@dimen/defaulttextsize</item> <item name="android:linespacingmultiplier">@dimen/defaultlinespacing</item> </style> <style name="zinedittext" parent="widget.holo.edittext"> <item name="zintypeface">light</item> <item name="android:textsize">@dimen/defaulttextsize</item> <item name="android:linespacingmultiplier">@dimen/defaultlinespacing</item> </style> as said, none of above seemed work.
so how 1 find actual parent style use?
to address immediate issue, default style appcompatedittext widget.appcompat.edittext. second example you've shown correct one:
<style name="zinedittext" parent="widget.appcompat.edittext"> ... this needs set edittextstyle in app theme.
<style name="apptheme" parent="@style/theme.appcompat"> <item name="edittextstyle">@style/zinedittext</item> ... finding these default styles , attributes not documented anywhere officially, far i'm aware. official documentation styles , themes directs 1 various r.attr pages framework , support packages, "discover" what's available. however, reliable way find views allow default style inspect source code.
a view subclass implement @ least 3 constructors: 1 takes context; 1 takes context , attributeset; , 1 takes context, attributeset, , int defstyleattr, default style attribute. attribute we're looking for. have sensible name, edittextstyle, textviewstyle, checkboxstyle, etc. if know name, can skip checking view class it.
in views chain constructors, attribute in call three-parameter constructor two-parameter one. in appcompatedittext, can see name of attribute edittextstyle.
public appcompatedittext(context context, attributeset attrs) { this(context, attrs, r.attr.edittextstyle); } after we've got name attribute, head res/values/ directory platform or support package view in. default value in relevant themes*.xml file app's parent theme.
for platform themes, there base themes.xml, , few others specific theme versions, such holo , material.
for support library views, these theme files under package-specific res/values/ directory, , default attribute value may in themes.xml or themes_base.xml.
in v7 appcompat, our app's exact parent theme in v7/appcompat/res/values/themes.xml, though of themes there direct aliases base themes; i.e., don't override of parents' attribute values. default appcompatedittext in v7/appcompat/res/values/themes_base.xml. there separate entries different themes - regular, , light - both same.
<item name="edittextstyle">@style/widget.appcompat.edittext</item> this enough determine style use our parent, should want check out style specifics, can refer v7/appcompat/res/values/styles.xml, find style's parent:
<style name="widget.appcompat.edittext" parent="base.widget.appcompat.edittext"/> which leads v7/appcompat/res/values/styles_base.xml:
<style name="base.widget.appcompat.edittext" parent="base.v7.widget.appcompat.edittext" /> <style name="base.v7.widget.appcompat.edittext" parent="android:widget.edittext"> <item name="android:background">?attr/edittextbackground</item> <item name="android:textcolor">?attr/edittextcolor</item> <item name="android:textappearance">?android:attr/textappearancemediuminverse</item> </style>
Comments
Post a Comment