android - 如何更改扩展 float 操作按钮的形状?

标签 android android-layout android-button floating-action-button material-components-android

我正在尝试将我的操作按钮的形状从这个默认形状更改为矩形。这是我的xml:

<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:cornerRadius="90dp"
        android:text="@string/create_player_text"
        android:fontFamily="@font/proximanova_semibold"
        app:layout_constraintHorizontal_bias="0.99"
        app:layout_constraintVertical_bias="0.01"/>

enter image description here

最佳答案

如果你想改变 ExtendedFloatingActionButton 的形状您可以使用 shapeAppearanceOverlay 布局中的属性:

    <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
        app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlayExtended"
        ../>

和:
  <style name="ShapeAppearanceOverlayExtended" parent="">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSize">0dp</item>
  </style>

如果您想要拐角半径,只需更改 <item name="cornerSize">0dp</item> 中的值即可。 .

enter image description here

关于android - 如何更改扩展 float 操作按钮的形状?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57860904/

相关文章:

android - 像谷歌地图一样在右下角添加自定义位置按钮

android - 在我自己的自定义 Android 主屏幕中,如何捕捉主页按钮?

javascript - AVG(COLUMN_SCORE) 未写入 SQLite 数据库

android - 使用 ADB 命令测量特定应用程序或包名称的电池消耗

Android - 在 onMeasure 中更改布局子项

java - 如何从 LinearLayout 中删除所有 LinearLayouts?

android - 在 Android 的按钮内居中大文本不起作用

android - 设置 android 按钮不可见但仍然附加了一个 onClick 监听器

android - 如果未指定,我在哪里可以找到使用的实际 android 构建工具版本

java - ArrayAdapter 中的内存泄漏