Android開發(fā)懸浮按鈕 Floating ActionButton的實現(xiàn)方法
一、介紹
這個類是繼承自ImageView的,所以對于這個控件我們可以使用ImageView的所有屬性
android.support.design.widget.FloatingActionButton
二、使用準(zhǔn)備, 在as 的 build.grade文件中寫上
compile 'com.android.support:design:22.2.0'
三、使用說明
xml文件中,注意藍(lán)色字體部分
<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ū)挾?,通常設(shè)置為0 ,用于解決Android 5.X設(shè)備上陰影無法正常顯示的問題
2、app:backgroundTint=""---------------按鈕的背景顏色,不設(shè)置,默認(rèn)使用theme中colorAccent的顏色
3、app:rippleColor=""--------------------點擊的邊緣陰影顏色
4、app:elevation=""----------------------邊緣陰影的寬度
5、app:pressedTranslationZ="16dp"-----點擊按鈕時,按鈕邊緣陰影的寬度,通常設(shè)置比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>
然后我們設(shè)置FloatActionButton的backgroud為這個drawable文件即可,同時app:backgroundTint=""屬性也可以不再設(shè)置
<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 應(yīng)用內(nèi)部懸浮可拖動按鈕簡單實現(xiàn)代碼
- Android實現(xiàn)系統(tǒng)級懸浮按鈕
- Android懸浮按鈕的使用方法
- Android懸浮窗按鈕實現(xiàn)點擊并顯示/隱藏多功能列表
- Android自定義APP全局懸浮按鈕
- Android利用WindowManager生成懸浮按鈕及懸浮菜單
- Android自定義懸浮按鈕效果
相關(guān)文章
解析:ClickOnce通過URL傳遞參數(shù) XXX.application?a=1
本篇文章是對ClickOnce通過URL傳遞參數(shù)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06android 網(wǎng)絡(luò)請求庫volley方法詳解
這篇文章主要介紹了android 網(wǎng)絡(luò)請求庫volley方法詳解的相關(guān)資料,需要的朋友可以參考下2016-09-09Android 點擊editview以外位置實現(xiàn)隱藏輸入法
這篇文章主要介紹了Android 點擊editview以外位置實現(xiàn)隱藏輸入法的相關(guān)資料,需要的朋友可以參考下2017-06-06Android開發(fā)之進(jìn)度條ProgressBar的示例代碼
本篇文章主要介紹了Android開發(fā)之進(jìn)度條ProgressBar的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-03-03Android 獲取瀏覽器當(dāng)前分享頁面的截屏示例
本篇文章主要介紹了Android 獲取瀏覽器當(dāng)前分享頁面的截屏示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02