Android開發(fā)懸浮按鈕 Floating ActionButton的實現(xiàn)方法
一、介紹
這個類是繼承自ImageView的,所以對于這個控件我們可以使用ImageView的所有屬性
android.support.design.widget.FloatingActionButton
二、使用準備, 在as 的 build.grade文件中寫上
compile 'com.android.support:design:22.2.0'
三、使用說明
xml文件中,注意藍色字體部分
<android.support.design.widget.FloatingActionButton android:id="@+id/floatingActionButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:src="@mipmap/ok" app:borderWidth="0dp" app:backgroundTint="#FF4011" app:rippleColor="#33728dff" app:elevation="8dp" app:pressedTranslationZ="16dp" />
可以看到我們使用了app屬性,則需要在根容器中添加這個屬性。
xmlns:app="http://schemas.android.com/apk/res-auto"
屬性介紹:
1、app:borderWidth=""------------------邊框?qū)挾?,通常設置為0 ,用于解決Android 5.X設備上陰影無法正常顯示的問題
2、app:backgroundTint=""---------------按鈕的背景顏色,不設置,默認使用theme中colorAccent的顏色
3、app:rippleColor=""--------------------點擊的邊緣陰影顏色
4、app:elevation=""----------------------邊緣陰影的寬度
5、app:pressedTranslationZ="16dp"-----點擊按鈕時,按鈕邊緣陰影的寬度,通常設置比elevation的數(shù)值大
另外我們希望點擊按鈕一個顏色,正常狀態(tài)一個顏色 以提高用戶體驗,那么就是drawable文件夾中創(chuàng)建文件 floatbutton.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/colorNormal"></item> <item android:state_pressed="true" android:drawable="@color/colorPressed"></item> </selector>
然后我們設置FloatActionButton的backgroud為這個drawable文件即可,同時app:backgroundTint=""屬性也可以不再設置
<android.support.design.widget.FloatingActionButton android:id="@+id/floatingActionButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="@drawable/floatbutton" android:src="@mipmap/ok" app:borderWidth="0dp" app:rippleColor="#33728dff" app:elevation="8dp" app:pressedTranslationZ="16dp" />
效果圖:

- Android仿知乎懸浮功能按鈕FloatingActionButton效果
- Android自定義可拖拽的懸浮按鈕DragFloatingActionButton
- Android開發(fā)之FloatingActionButton懸浮按鈕基本使用、字體、顏色用法示例
- android 應用內(nèi)部懸浮可拖動按鈕簡單實現(xiàn)代碼
- Android實現(xiàn)系統(tǒng)級懸浮按鈕
- Android懸浮按鈕的使用方法
- Android懸浮窗按鈕實現(xiàn)點擊并顯示/隱藏多功能列表
- Android自定義APP全局懸浮按鈕
- Android利用WindowManager生成懸浮按鈕及懸浮菜單
- Android自定義懸浮按鈕效果
相關文章
android系統(tǒng)拍照結(jié)合android-crop裁剪圖片
這篇文章主要為大家詳細介紹android系統(tǒng)拍照結(jié)合android-crop裁剪圖片,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-01-01
android開發(fā)之為activity增加左右手勢識別示例
這篇文章主要介紹了android開發(fā)中為activity增加左右手勢識別示例,需要的朋友可以參考下2014-04-04
解決Android加殼過程中mprotect調(diào)用失敗的原因分析
本文探討的主要內(nèi)容是mprotect調(diào)用失敗的根本原因,以及在加殼實現(xiàn)中的解決方案,通過本文的闡述,一方面能夠幫助遇到同類問題的小伙伴解決心中的疑惑,另一方面能夠給大家提供可落地的實現(xiàn)方案,需要的朋友可以參考下2022-01-01
android基于ListView和CheckBox實現(xiàn)多選和全選記錄的功能
本篇文章主要介紹了android基于ListView和CheckBox實現(xiàn)多選和全選記錄的功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2016-11-11
Android開發(fā)之拼音轉(zhuǎn)換工具類PinyinUtils示例
這篇文章主要介紹了Android開發(fā)之拼音轉(zhuǎn)換工具類PinyinUtils,涉及Android基于pinyin4j-2.5.0.jar包文件實現(xiàn)漢字轉(zhuǎn)拼音功能的相關操作技巧,需要的朋友可以參考下2017-11-11
分享安裝Android Studio3.6的經(jīng)驗教訓
這篇文章主要介紹了Android Studio3.6的安裝錯誤問題及解決方法,非常值得大家參考,現(xiàn)把整個過程分享到腳本之家平臺,需要的朋友參考下吧2020-02-02

