Android 不通过parent实现样式继承

1:styles.xml文件内容如下:

<!-- TextView Style -->
    <style name="tvStyle">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:typeface">monospace</item>
    </style>
    <style name="tvStyle.Red">
        <item name="android:textColor">#FF0000</item>
    </style>

首先定义了一个tvStyle的样式,如果想在tvStyle样式的基础上新增加一些样式,可以通过tvStyle.Red的方式实现。

2:使用方式如下:

<TextView
        android:id="@+id/tvOne"
        style="@style/tvStyle"
        android:text="@string/hello_world"/>

    <TextView
        android:layout_below="@id/tvOne"
        style="@style/tvStyle.Red"
        android:text="@string/hello_world"/>

3:效果如下:

原文地址:https://www.cnblogs.com/yshyee/p/3403368.html