您好,登錄后才能下訂單哦!
本篇文章為大家展示了Android項目中如何修改FloatingActionButton中title的文字與背景顏色,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
首先看一張圖片
我是在一個不錯的開源的FloatingActionButton庫基礎(chǔ)上實現(xiàn)的,鏈接github開源庫 參考圖片的標記和代碼里的注釋。代碼如下:
<com.getbase.floatingactionbutton.FloatingActionsMenu android:id="@+id/fab_meau" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" fab:fab_addButtonColorNormal="@color/theme_color" //修改meau按鈕的背景色 fab:fab_addButtonColorPressed="@color/fab_pressed_color" //meau按鈕按下的顏色 fab:fab_addButtonPlusIconColor="@color/white" //meau中間 "+" 的顏色 fab:fab_labelStyle="@style/fab_labels_style" //title樣式,可以修改title的顏色和背景 android:layout_marginBottom="16dp" android:layout_marginRight="16dp" android:layout_marginEnd="16dp"> <com.getbase.floatingactionbutton.FloatingActionButton android:id="@+id/fab_action_a" android:layout_width="wrap_content" android:layout_height="wrap_content" fab:fab_colorNormal="@color/white" fab:fab_title="聯(lián)系客服發(fā)布信息" //button的標題 fab:fab_size="mini" //normal和mini兩個值,normal和meau一樣大 /> <com.getbase.floatingactionbutton.FloatingActionButton android:id="@+id/fab_action_b" android:layout_width="wrap_content" android:layout_height="wrap_content" fab:fab_colorNormal="@color/white" fab:fab_title="個人發(fā)布信息" fab:fab_size="mini" fab:fab_colorPressed="@color/fab_pressed_color" /> </com.getbase.floatingactionbutton.FloatingActionsMenu>
在value.xml配置樣式fab_labels_style代碼如下:
<style name="fab_labels_style"> <item name="android:background">@drawable/fab_label_background</item> //文字背景的樣式 <item name="android:textColor">@color/black</item> //文字的顏色 </style>
drawable文件夾下的fab_label_background.xml代碼如下:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@color/white"/> <padding android:left="16dp" android:top="4dp" android:right="16dp" android:bottom="4dp"/> //離內(nèi)邊框的距離 <corners android:radius="5dp"/> //邊框四個叫的弧度 <stroke android:width="1dp" android:color="@color/text_color_84"/> //邊框邊線的寬度和顏色 </shape>
上述內(nèi)容就是Android項目中如何修改FloatingActionButton中title的文字與背景顏色,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。