如何在自定义styles.xml中继承默认的Android样式?

时间:2015-11-30 17:41:01

标签: android android-layout android-edittext textview android-styles

我目前正在为'styles.xml'中定义的EditTexts使用此自定义样式布局:

<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>

然而,现在我的困境发生了,因为我有一个TextView,我希望将其设置为默认的Android EditText,但随后也应用我的上述自定义样式。默认的Android样式如下所示:

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

我知道在布局样式文件中可以继承,但是如何在自定义样式中继承Android默认样式,以实现与此类似的东西:

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

1 个答案:

答案 0 :(得分:3)

继承其他一些风格的最简单方法是使用parent属性:

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

正如@Bobby StJacques所指出的,如果你想继承你定义的(不是内置的Android)样式,你可以使用以下形式:

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

在这种情况下,您将继承已定义的Form_EditView

相关问题