如果我有很多TextViews用作项目标签,我想我可以将关于它们的所有通用内容提取为一种样式,并且仅在布局中使用

<TextView style="@style/label" android:text="Foo"/>
<TextView style="@style/label" android:text="Bar"/>

样式如下:
<style name="label">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
</style>

但是,当我这样做时,它可以在模拟器和设备上正常工作,但是Android XML编辑器会提示"<TextView>" does not set the required layout_height attribute.有什么理由为什么要报告此警告?

最佳答案

您是否尝试过清理项目?

我还在某些XML文件上使用相同的东西作为宽度和长度。
这是在我的应用程序上工作的示例,您可以看一下:

<TextView
    android:id="@+id/viewdescription"
    android:textIsSelectable="true"
    android:layout_below="@+id/rating_bar_view"
    android:minLines="8"
    style="@style/description" />

和XML:
<style name="description">
   <item name="android:layout_gravity">center_horizontal</item>
   <item name="android:inputType">textMultiLine</item>
   <item name="android:layout_width">fill_parent</item>
   <item name="android:layout_height">wrap_content</item>
   <item name="android:textSize">14sp</item>
   <item name="android:textColor">@color/Black</item>
   <item name="android:layout_marginRight">8dp</item>
   <item name="android:layout_marginLeft">8dp</item>

10-07 19:25
查看更多