我的 axml 文件中有几个 View 小部件,它们看起来像这样:
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_marginTop="1dp"
android:layout_marginBottom="5dp"
android:background="#c0c0c0" />
我不想重复代码,所以我在 Values 文件夹中创建了 style.xml 文件,内容如下:
<resources>
<style name="HorizontalLine">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">2dp</item>
<item name="android:layout_marginTop">1dp</item>
<item name="marginBottom">5dp</item>
<item name="android:background">#c0c0c0</item>
</style>
</resources>
现在我正在尝试在我的视图中引用样式:
<View
android:style="@style/HorizontalLine"
/>
但它不起作用。我已经尝试了所有在互联网上创造风格。我错在哪里?
这里是关于如何在 Xamarin.Android 中使用样式
用这个替换你的代码:
styles.xml
:
<resources>
<style name="HorizontalLine">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">2dp</item>
<item name="android:layout_marginTop">1dp</item>
<item name="android:layout_marginBottom">5dp</item>
<item name="android:background">#c0c0c0</item>
</style>
</resources>
<item name="marginBottom">5dp</item>
它不能被编译器识别。
layout.xml
:
<View
style="@style/HorizontalLine"
/>
替换android:style=
为style=
,您可以在链接中看到它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句