[英]How to add a border in floating action button
我有一个带有全白色背景色和图像源的浮动按钮。 我想用灰色边框包围它。 我找不到任何办法。 请帮忙。
我刚刚创建了一个普通的FAB。
这是我按钮的XML代码。
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="normal"
android:src="@drawable/addvideo"
app:backgroundTint="#fff"
app:layout_anchor="@+id/bottomAppBar"
android:scaleType="center"
android:id="@+id/myFab"
/>
解决方法是,可以执行以下步骤:
fab_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
android:shape="ring"
android:thicknessRatio="2"
android:useLevel="false" >
<solid android:color="@android:color/transparent" />
<!-- here set the width and color of your border -->
<stroke
android:width="5dp"
android:color="@android:color/darker_gray" />
</shape>
您的主要布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- the wrapper layout having a padding with the size of your border -->
<!-- and background set to the custom drawable file -->
<LinearLayout
android:id="@+id/fabWrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="@drawable/fab_background"
android:padding="5dp"
>
<android.support.design.widget.FloatingActionButton
android:id="@+id/myFab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
app:fabSize="normal"
android:src="@drawable/addvideo"
android:backgroundTint="@android:color/white"
/>
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.