Android android 可绘制对象上不存在 FAB 加号
Android FAB plus sign not present on android drawable
在哪里可以找到浮动操作按钮中心的加号?
是Android制作的还是需要我自己制作?
您可以获得 Material 个图标:
1.在线 - 来自Material Design Website。加号图标称为 'add'。 Select 图标,选择颜色和尺寸并下载 png 或 svg 资源。
2.来自 Android Studio - 使用 Vector Asset Studio。查看 link 了解更多信息。 (正如 Wilder Pereira 在下面 post 中所建议的那样 )
您可以在 Vector Asset Studio 上找到加号图标。
- 在 Android Studio 中,打开一个 Android 应用程序项目。
- 在项目 window 中,select Android 视图。
- 右键单击 res 文件夹,然后 select 新建 > 矢量资源。
- 单击 Android 图标按钮并查找加号
更多信息在这里:https://developer.android.com/studio/write/vector-asset-studio.html#materialicon
如果您需要更改颜色,请更改 fab 上的着色方法。例如,我的晶圆厂需要 "white plus",所以我这样做了:
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:tint="@android:color/white" //put your colors here
android:src="@drawable/ic_add_black_24dp"
android:layout_height="wrap_content" />
根据@Dagnogo的回答,我发现这是最简单的方法。
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_input_add"
android:tint="@android:color/white"/>
钥匙正在使用色调属性
我想你正在搜索这个。
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_input_add" />
2021 年,如果要更改按钮的颜色,则需要使用 app:tint
属性 而不是 android:tint
。
此外,我建议使用 app:srcCompat
而不是 android:src
,以便更好地支持 。
为了获得更好的辅助功能支持,使用 android:contentDescription
属性很重要。
最后,您可以使用 @android:drawable/
前缀使用内置绘图。
综合起来:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="32dp"
android:contentDescription="Add a new item"
app:tint="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@android:drawable/ic_input_add" />
在哪里可以找到浮动操作按钮中心的加号?
是Android制作的还是需要我自己制作?
您可以获得 Material 个图标:
1.在线 - 来自Material Design Website。加号图标称为 'add'。 Select 图标,选择颜色和尺寸并下载 png 或 svg 资源。
2.来自 Android Studio - 使用 Vector Asset Studio。查看 link 了解更多信息。 (正如 Wilder Pereira 在下面 post 中所建议的那样 )
您可以在 Vector Asset Studio 上找到加号图标。
- 在 Android Studio 中,打开一个 Android 应用程序项目。
- 在项目 window 中,select Android 视图。
- 右键单击 res 文件夹,然后 select 新建 > 矢量资源。
- 单击 Android 图标按钮并查找加号
更多信息在这里:https://developer.android.com/studio/write/vector-asset-studio.html#materialicon
如果您需要更改颜色,请更改 fab 上的着色方法。例如,我的晶圆厂需要 "white plus",所以我这样做了:
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:tint="@android:color/white" //put your colors here
android:src="@drawable/ic_add_black_24dp"
android:layout_height="wrap_content" />
根据@Dagnogo的回答,我发现这是最简单的方法。
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_input_add"
android:tint="@android:color/white"/>
钥匙正在使用色调属性
我想你正在搜索这个。
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_input_add" />
2021 年,如果要更改按钮的颜色,则需要使用 app:tint
属性 而不是 android:tint
。
此外,我建议使用 app:srcCompat
而不是 android:src
,以便更好地支持
为了获得更好的辅助功能支持,使用 android:contentDescription
属性很重要。
最后,您可以使用 @android:drawable/
前缀使用内置绘图。
综合起来:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="32dp"
android:contentDescription="Add a new item"
app:tint="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@android:drawable/ic_input_add" />