UIAndroid控件

FloatingActionButton的简单使用

2018-08-13  本文已影响1977人  itfitness

FloatingActionButton是Support Design Library库中引入的一个新的控件,外观时尚新颖,受到很多开发者的好评。

如何使用FloatingActionButton

使用FloatingActionButton其实非常简单只需要在布局文件中引入控件即可,不过它的属性有点多,我们先来介绍一下它的属性。

讲完属性接下来实现一下效果

xml布局文件
<FrameLayout
    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">

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_gravity="end|bottom"
        android:id="@+id/floatbutton"
        app:elevation="6dp"
        android:clickable="true"
        app:borderWidth="0dp"
        android:backgroundTint="@color/fabbg"
        app:rippleColor="#0097a7"
        android:layout_marginBottom="20dp"
        android:layout_marginRight="20dp"
        android:src="@drawable/ic_logo"
        app:pressedTranslationZ="12dp"
        android:layout_height="wrap_content" />

</FrameLayout>
color/fabbg.xml文件,这个需要在res目录下新建color文件夹
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="false" android:color="#00b8d4"/>
    <item android:state_focused="true" android:color="#00e5ff"/>
</selector>
FloatingActionButton的点击事件与Button的实现方式一样,这里不予演示
运行效果
GIF.gif

个人博客:https://myml666.github.io

上一篇 下一篇

猜你喜欢

热点阅读