我有一个单独的设计库,用于共享UI组件和样式。
<style name="Button.Secondary" parent="Button">
<item name="android:background">@drawable/secondary_button_state</item>
<item name="android:textColor">@color/blue</item>
</style>
<style name="Button.Secondary.Large" parent="Button.Secondary">
<item name="android:drawableRight">@drawable/ic_chevron</item>
<item name="android:drawableTint">?android:colorSecondary</item>
<item name="android:paddingStart">8dp</item>
<item name="android:paddingEnd">8dp</item>
<item name="android:gravity">center|start</item>
<item name="android:textAppearance">@style/Subhead.Large</item>
<item name="android:fontFamily">sans-serif-thin</item>
</style>
在我的应用程序中,我使用了我的设计库中的按钮样式属性。
<Button
android:id="@+id/share_button"
style="@style/Button.Secondary.Large"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Share Crew"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/crew_specialty_label" />
API 25及更高版本,工作正常,没有问题。API 24和更低的使用该样式的组件无法充气。
android.view.InflateException: Binary XML file line #100: Binary XML file line #100: Error inflating class Button
Caused by: android.view.InflateException: Binary XML file line #100: Error inflating class Button
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 79: TypedValue{t=0x2/d=0x1010530 a=3}