Android:如何更改浮动操作按钮的 app:fabSize="normal" 的大小
Android: How to change size of app:fabSize="normal" for Floating Action Button
使用新的FloatingActionButton
时,大小由app:fabSize="normal"
决定。如何设置 dp
中的大小是 "normal"
引用的大小?
我尝试创建 values/attrs.xml
:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="app">
<attr name="fabSize">
<enum name="mini" value="50dp" />
<enum name="normal" value="100dp" />
</attr>
</declare-styleable>
</resources>
但是我得到了错误
"normal" in attribute "fabSize" is not a valid integer
有两种不同尺寸的 FAB
可供选择:normal
或 mini
Normal (56dp)
— 大多数情况下应该使用这个尺寸。
Mini (40dp)
— 只应在需要与屏幕上显示的其他组件保持视觉连续性时使用。
我知道不推荐这样做,但对于那些绝对需要更改默认大小的人,我可以通过将 FloatingActionButton
包装在 LinearLayout
.
中来实现
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerInParent="true"
android:orientation="horizontal" >
<android.support.design.widget.FloatingActionButton
android:layout_width="@dimen/custom_fab_size"
android:layout_height="@dimen/custom_fab_size"
app:fabSize="normal"
android:clickable="true"
android:src="@drawable/ic_mic_white_24dp"
android:scaleType="center"/>
</LinearLayout>
您可以通过将以下内容添加到 values/dimens.xml
来覆盖普通尺寸和迷你尺寸:
<!-- Overriding sizes of the FAB -->
<dimen name="design_fab_size_normal">90dp</dimen>
<dimen name="design_fab_size_mini">30dp</dimen>
棘手的事情是,如果您需要超过 2 个晶圆厂尺寸,在这种情况下,我想您需要创建一个扩展晶圆厂的自定义视图。
<dimen name="design_fab_size_normal">90dp</dimen>
<dimen name="design_fab_size_mini">30dp</dimen>
Set this in dimen file.
只有 app:fabCustomSize 在 xml
中的用户
app:fabCustomSize="100dp"
宾果。
• Standard Sizes
标准 FAB
尺寸(根据 developer.android)有三个选项,您可以使用 app:fabSize
.
设置它们
- normal: 正常大小的按钮。
- mini: 迷你按钮。
- auto:大小会根据window大小
改变
.
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_add_black_24dp"
app:tint="#404D54"
app:backgroundTint="#ffd500"
app:fabSize="normal" />
.
• Custom Sizes
要设置自定义 FAB
大小,您可以设置 app:fabCustomSize
。注意 android:layout_width
和 android:layout_height
应该是 "wrap_content"
.
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_add_black_24dp"
app:tint="#404D54"
app:backgroundTint="#ffd500"
app:fabCustomSize="36dp" />
为了更改 Fab 大小并查看大图像初始化,我在 android api 28 中进行了以下更改:- 它们与
<android.support.design.widget.FloatingActionButton
android:id="@+id/profile_imageview"
android:layout_width="@dimen/design_fab_size_mini"
android:layout_height="@dimen/design_fab_size_mini"
android:layout_marginTop="10dp"
android:src="@drawable/pin_check"
app:borderWidth="0dp"
app:elevation="0dp"
app:maxImageSize="90dp" />
在 dimens.xml
中
<dimen name="design_fab_size_mini" tools:override="true">90dp</dimen>
<dimen name="design_fab_content_size" tools:override="true">58dp</dimen>
应用程序:最大图像大小
<android.support.design.widget.FloatingActionButton
android:id="@+id/floating_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginBottom="60dp"
android:src="@drawable/icon_return_back"
app:backgroundTint="#00ffffff"
app:borderWidth="0dp"
app:elevation="0dp"
app:maxImageSize="46dp"
app:pressedTranslationZ="0dp"
app:rippleColor="#00ffffff" />
只需在 FAB 组件下的 xml 文件中添加 app:fabCustomSize="70dp"
这是 FAB 按钮的示例:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_AddRoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="@android:drawable/ic_input_add"
app:fabCustomSize="70dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.93"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.93" />
使用新的FloatingActionButton
时,大小由app:fabSize="normal"
决定。如何设置 dp
中的大小是 "normal"
引用的大小?
我尝试创建 values/attrs.xml
:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="app">
<attr name="fabSize">
<enum name="mini" value="50dp" />
<enum name="normal" value="100dp" />
</attr>
</declare-styleable>
</resources>
但是我得到了错误
"normal" in attribute "fabSize" is not a valid integer
有两种不同尺寸的 FAB
可供选择:normal
或 mini
Normal (56dp)
— 大多数情况下应该使用这个尺寸。Mini (40dp)
— 只应在需要与屏幕上显示的其他组件保持视觉连续性时使用。
我知道不推荐这样做,但对于那些绝对需要更改默认大小的人,我可以通过将 FloatingActionButton
包装在 LinearLayout
.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerInParent="true"
android:orientation="horizontal" >
<android.support.design.widget.FloatingActionButton
android:layout_width="@dimen/custom_fab_size"
android:layout_height="@dimen/custom_fab_size"
app:fabSize="normal"
android:clickable="true"
android:src="@drawable/ic_mic_white_24dp"
android:scaleType="center"/>
</LinearLayout>
您可以通过将以下内容添加到 values/dimens.xml
来覆盖普通尺寸和迷你尺寸:
<!-- Overriding sizes of the FAB -->
<dimen name="design_fab_size_normal">90dp</dimen>
<dimen name="design_fab_size_mini">30dp</dimen>
棘手的事情是,如果您需要超过 2 个晶圆厂尺寸,在这种情况下,我想您需要创建一个扩展晶圆厂的自定义视图。
<dimen name="design_fab_size_normal">90dp</dimen>
<dimen name="design_fab_size_mini">30dp</dimen>
Set this in dimen file.
只有 app:fabCustomSize 在 xml
中的用户app:fabCustomSize="100dp"
宾果。
• Standard Sizes
标准 FAB
尺寸(根据 developer.android)有三个选项,您可以使用 app:fabSize
.
- normal: 正常大小的按钮。
- mini: 迷你按钮。
- auto:大小会根据window大小 改变
.
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_add_black_24dp"
app:tint="#404D54"
app:backgroundTint="#ffd500"
app:fabSize="normal" />
.
• Custom Sizes
要设置自定义 FAB
大小,您可以设置 app:fabCustomSize
。注意 android:layout_width
和 android:layout_height
应该是 "wrap_content"
.
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_add_black_24dp"
app:tint="#404D54"
app:backgroundTint="#ffd500"
app:fabCustomSize="36dp" />
为了更改 Fab 大小并查看大图像初始化,我在 android api 28 中进行了以下更改:- 它们与
<android.support.design.widget.FloatingActionButton
android:id="@+id/profile_imageview"
android:layout_width="@dimen/design_fab_size_mini"
android:layout_height="@dimen/design_fab_size_mini"
android:layout_marginTop="10dp"
android:src="@drawable/pin_check"
app:borderWidth="0dp"
app:elevation="0dp"
app:maxImageSize="90dp" />
在 dimens.xml
中<dimen name="design_fab_size_mini" tools:override="true">90dp</dimen>
<dimen name="design_fab_content_size" tools:override="true">58dp</dimen>
应用程序:最大图像大小
<android.support.design.widget.FloatingActionButton
android:id="@+id/floating_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginBottom="60dp"
android:src="@drawable/icon_return_back"
app:backgroundTint="#00ffffff"
app:borderWidth="0dp"
app:elevation="0dp"
app:maxImageSize="46dp"
app:pressedTranslationZ="0dp"
app:rippleColor="#00ffffff" />
只需在 FAB 组件下的 xml 文件中添加 app:fabCustomSize="70dp"
这是 FAB 按钮的示例:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_AddRoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="@android:drawable/ic_input_add"
app:fabCustomSize="70dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.93"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.93" />