我在ids.xml - > <item name="example" type="id"/>
中定义了ID
我在styles.xml中使用了这个ID,就像这样 - >
<style name="exampleStyle">
<item name="android:id">@id/example</item>
###rest of items (width, height etc.)
</style>
我在我的ConstraintLayout中使用了这种风格 - >
<Button
android:id="@+id/testButton"
android:layout_width="200dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toStartOf="@+id/goNextButton"/>
<ImageView
style="@style/exampleStyle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
最后IDE(Android studio)显示错误“id示例已定义但未分配给任何视图。
为什么它没有看到我只是通过样式使用此ID?我可以在不使用tools:ignore="UnknownId
的情况下解决这个问题吗?
而不是在风格中使用“android:id
”,而是在ImageView
中使用它
作为一个布局的例子,它可能有几个ImageView
。所以你可以多次使用相同的风格。但如果操作基于id,那么您无法正确使用它。