android - 带有文本而不是图像的 FloatingActionButton

标签 android material-design android-support-library floating-action-button

我试图弄清楚如何从 android 支持库中修改 FloatingActionButton。可以用文字代替图片吗?

类似这样的:

enter image description here

我看到它扩展了 ImageButton,所以我认为不是。我说的对吗?

就 Material 设计而言,这是否正确?

最佳答案

谢谢大家。

这是我为这个问题找到的简单解决方法。适用于 Android 4+,Android 5+ 添加了特定参数 android:elevation 以在 FloatingActionButton 上绘制 TextView。

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right">

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@android:color/transparent" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@android:string/ok"
        android:elevation="16dp"
        android:textColor="@android:color/white"
        android:textAppearance="?android:attr/textAppearanceMedium" />
</FrameLayout>

关于android - 带有文本而不是图像的 FloatingActionButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33671196/

相关文章:

android - 来自android中url的图库图片?

Android 12 工作配置文件设备识别

Android 纹波和时序

android - 了解 appcompact values-v11/themes_base.xml 错误

android - recyclerview 的所有版本在哪里?

android - 组织.gradle.api.tasks.TaskExecutionException : Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'

android 如何通过 onItemClick 监听器从 GridView 获取图像路径

angularjs - NgMaterial/Material Design 涟漪效应正在渗透边缘

c# - 如何使用代码在 C# 中调用 materialDesign 组件并添加到 wpf 设计中?

Android edittext更改弹出上下文菜单样式