How do I inherit from default Android style in my custom styles.xml?

穿精又带淫゛_ 提交于 2019-12-23 16:34:32

问题


I am currently using this custom styles layout for my EditTexts defined in 'styles.xml':

<style name="Form_EditView">
    <item name="android:textColor">@color/white</item>
    <item name="android:textSize">@dimen/large_text_size</item>
    <item name="colorControlNormal">@color/white</item>
    <item name="colorControlActivated">@color/pink</item>
    <item name="colorControlHighlight">@color/pink</item>
</style>

However now my dilemma occurs as I have a TextView that I would like to be styled like a default Android EditText but then to also apply my above custom styling. The default Android style is the one displayed below:

style="@android:style/Widget.EditText"

I know that inheritance is possible in layout styles files but how do I go about inheriting from Android default styles in my custom styles, to achieve something similar to this:

<style name="Widget.EditText.Form_EditView">

回答1:


The simplest way to inherit some other style - is to use parent attribute:

<style name="Form_EditView" parent="@android:style/Widget.EditText">

As @Bobby StJacques pointed out, if you want to inherit styles you defined (not built-in Android ones), you can use the following form:

<style name="Form_EditView.SomeCustomizedEditView">
    ....
</style>

In this case you inherit your already defined Form_EditView



来源:https://stackoverflow.com/questions/34004674/how-do-i-inherit-from-default-android-style-in-my-custom-styles-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!