我可以定义一个包含 Android 中的样式的样式吗?

Can I define a style that includes a style in Android?

我创建了以下样式:

<style name="wrap_content">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
</style>

我想创建第二个使用该样式的样式。我知道我可以做到以下几点:

<style name="cycle_radio_button" parent="wrap_content">
    <item name="android:layout_marginStart">1dp</item>
    <item name="android:layout_marginEnd">1dp</item>
</style>

但是有没有办法像下面这样做:

<style name="cycle_radio_button">
    <item name="android:layout_marginStart">1dp</item>
    <item name="android:layout_marginEnd">1dp</item>
    <item name="style">@style/wrap_content</item>
</style>

如果可以的话,基于我定义的多个其他样式创建样式会更容易、更清晰,而不是必须创建继承样式链。

您不能继承 Android 中的多个 xml 样式。最接近的是为特定类型的视图继承样式。例如:

<style name="style1" parent="Theme.AppCompat.Light">
    <item name="android:listViewStyle">@style/wrap_content</item>
    <item name="android:mapViewStyle">@style/AppTheme</item>
</style>

现在,任何继承自 "style1" 的列表视图或地图视图都将继承 "wrap_content" 中的样式。

name="android:listViewStyle" 等属性仅适用于特定视图类型,因此这不会完全满足您的要求。