ExtendedFloatingActionButton - как добиться такой же высоты, когда кнопка растянута, как при сжатии - PullRequest
2 голосов
/ 07 октября 2019

Я использую новейшие компоненты материала - 1.1.0-бета01.

Когда ExtendedFloatingActionButton расширяется, его высота также уменьшается.

fab shrinked

fab expanded

Вот как выглядит макет XML:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:id="@+id/main_view"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context=".MainActivity">

   <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
       android:id="@+id/fab"
       android:layout_width="wrap_content"
       android:layout_height="56dp"
       android:text="Text"
       android:textColor="#02220D"
       android:backgroundTint="#F2C203"
       style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton"
       android:textSize="15sp"
       android:fontFamily="sans-serif-medium"
       android:textStyle="normal"
       android:layout_marginBottom="16dp"
       android:layout_marginEnd="16dp"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintEnd_toEndOf="parent"
       app:iconTint="#02220D"
       app:icon="@drawable/ic_camera"
       app:iconPadding="10dp"
       android:insetLeft="0dp"
       android:insetBottom="0dp"
       android:insetTop="0dp"
       android:insetRight="0dp"
       />

</androidx.constraintlayout.widget.ConstraintLayout>

Я пытался установить минимальную и максимальную высоту, но это не сработало. Есть идеи, как достичь такой же высоты, когда кнопка растянута и сжата?

Спасибо.

Ответы [ 2 ]

1 голос
/ 07 октября 2019

ExtendedFloatingActionButton является MaterialButton.
. Вы можете использовать атрибут android:minHeight:

<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
    android:minHeight="56dp"
    ../>

enter image description here

В противном случаеВы можете определить собственный стиль:

 <style name="CustomExtendedFloating"  parent="Widget.MaterialComponents.ExtendedFloatingActionButton.Icon">
    <item name="android:minHeight">56dp</item>
 </style>
0 голосов
/ 10 октября 2019

Стоит отметить, что, согласно спецификации FAB и Extended FAB, в расширенном состоянии он не такой высокий. https://material.io/components/buttons-floating-action-button/#specs

...