Android 在样式中使用应用程序命名空间
我将举一个例子来说明更重要的一点 想象一下,我的应用程序有许多浮动操作按钮。因此,我想创建一种样式并重用它。因此,我做了以下工作:Android 在样式中使用应用程序命名空间,android,android-layout,android-theme,android-styles,Android,Android Layout,Android Theme,Android Styles,我将举一个例子来说明更重要的一点 想象一下,我的应用程序有许多浮动操作按钮。因此,我想创建一种样式并重用它。因此,我做了以下工作: <style name="FabStyle” parent ="Widget.Design.FloatingActionButton"> <item name="android:layout_width">wrap_content</item> <item name="android:layout_heigh
<style name="FabStyle” parent ="Widget.Design.FloatingActionButton">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_margin">16dp</item>
<item name="app:backgroundTint">@color/accent</item>
<item name="app:layout_anchorGravity">end|bottom</item>
</style>
我试图通过resources
标记引入名称空间,但这不起作用
<resources
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
>
你知道我该怎么做吗?对于
app
名称空间,你不需要指定app:
。只要
就足够了
例如
包装内容
包装内容
16dp
@颜色/口音
端部|底部
对于
layout\u anchorGravity
您需要在定义浮动操作按钮的XML文件中设置它。您可以直接使用该属性,而无需app
<style name="FabStyle” parent ="Widget.Design.FloatingActionButton">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_margin">16dp</item>
<item name="backgroundTint">@color/accent</item>
<item name="layout_anchorGravity">end|bottom</item>
</style>
太棒了!谢谢你的帮助。次要更正:您也可以在样式页上定义layout\u anchogravity
。它的作用是end | bottom
您保存了这一天!本地定义的是layout\u-anchor
+1.相关的:
<style name="FabStyle" parent="Widget.Design.FloatingActionButton">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_margin">16dp</item>
<item name="backgroundTint">@color/accent</item>
<item name="layout_anchorGravity">end|bottom</item>
</style>
<style name="FabStyle” parent ="Widget.Design.FloatingActionButton">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_margin">16dp</item>
<item name="backgroundTint">@color/accent</item>
<item name="layout_anchorGravity">end|bottom</item>
</style>