简体   繁体   English

如何更改扩展浮动操作按钮的形状?

[英]How do I change shape of Extended Floating Action Button?

I am trying to change the shape of my action button from this default shape to a rectangle.我正在尝试将我的操作按钮的形状从这个默认形状更改为矩形。 Here is my xml:这是我的 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"/>

在此处输入图片说明

If you want to change the shape of the ExtendedFloatingActionButton you can use the shapeAppearanceOverlay attribute in the layout:如果要更改ExtendedFloatingActionButton的形状,可以在布局中使用shapeAppearanceOverlay属性:

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

With:和:

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

If you want a corner radius just change the value in the <item name="cornerSize">0dp</item> .如果您想要一个圆角半径,只需更改<item name="cornerSize">0dp</item>

在此处输入图片说明

I think Material Button would fit perfectly regarding to your needed, also Material Button have rectangular shape with small radius in corners.我认为 Material Button 非常适合您的需要,而且 Material Button 具有矩形形状,拐角半径小。 You should try it instead using Extended Floating Action Button.您应该尝试使用扩展浮动操作按钮。

Check the Official document how to use it with guidelines查看官方文档如何使用指南

Material Button 材质按钮

Create an xml file like this:像这样创建一个xml文件:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape
            android:shape="rectangle">
            <corners android:radius="@dimen/_100sdp"/>
        </shape>
    </item>
</layer-list>

and use it in ur extended fab - use with shapeAppearanceOverlay并在您的扩展工厂中使用它 - 与shapeAppearanceOverlay使用

<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
            style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:shapeAppearanceOverlay="@drawable/bg_circle_black"
            android:text="Sign in to setup follow page"
            android:textAlignment="center"
            app:layout_anchor="@id/scrollView"
            app:layout_anchorGravity="bottom|center|center_horizontal" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM