如何在 android xml 中的 component/view 中添加 2 种样式

How to add 2 styles in a component/view in android xml

我想在ProgressBar

中添加两种样式

这是 ProgressBar

的 xml
<ProgressBar
        style="?android:attr/progressBarStyle"
        android:visibility="gone"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:id="@+id/progressBar"
        android:layout_marginTop="@dimen/margin_xxlarge_xxl"/>

我在 res/values/styles.xml

中定义了一个样式
<style name="genericRegView">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_marginTop">@dimen/margin_xxlarge_xxl</item>
    </style>

我想将 genericRegView 应用到 ProgressBar,但如您所见,它已经附加了样式。我怎样才能同时添加两者?

我知道我可以通过样式 XML 文件中的名称继承样式,但是 ProgressBar 样式是 ?android:attr/progressBarStyle 所以我不知道如何继承它

您可以使用 parent 属性继承 ProgressBar 样式

<style name="genericRegView" parent="Widget.AppCompat.ProgressBar">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_marginTop">@dimen/margin_xxlarge_xxl</item>
</style>

并将 genericRegView 样式应用于 ProgressBar