Android 未讀消息的紅點顯示
在很多APP里面,經(jīng)常會看到未讀消息的小紅點,如下圖:

這個功能用到的是一個控件,叫做BadgeView。
BadgeView的用法很簡單,直接把jar文件導(dǎo)入包中就可以使用,使用也很簡單,
badgeView = new BadgeView(this); //btn是控件 badgeView.setTargetView(btn); //設(shè)置相對位置 badgeView.setBadgeMargin(0, 5, 15, 0); //設(shè)置顯示未讀消息條數(shù) badgeView.setBadgeCount(2);
BadgeView可以在任意控件上使用。但是在Radiobutton構(gòu)成的底部導(dǎo)航里面,如果直接在Radiobutton上使用的話,會使Radiobutton的點擊失效。
解決辦法就是,在Radiobutton上加一層布局,然后布局設(shè)置為不可點擊,我這里用的是button。
布局只是用來顯示未讀消息個數(shù)。
布局代碼:
<RadioGroup android:id="@+id/main_radio" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:background="#121212" android:gravity="center_vertical" android:orientation="horizontal"> <RadioButton android:id="@+id/radio_button0" style="@style/main_tab_bottom" android:layout_marginTop="5.0dip" android:drawableTop="@drawable/home_btn_1" android:text="@string/main_home" android:textColor="@drawable/color_radiobtton" android:textSize="10.0sp" /> </RadioGroup> <!-- 實現(xiàn)提醒信息用的 --> <LinearLayout android:layout_width="fill_parent" android:layout_height="50dp" android:background="#00000000" android:orientation="horizontal" > <Button android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="1" android:clickable="false" android:background="#00000000" /> </LinearLayout>
包的下載鏈接:
http://xiazai.jb51.net/201704/yuanma/badgeview_jb51.rar
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
相關(guān)文章
android View 繪制完成監(jiān)聽的實現(xiàn)方法
今天小編就為大家分享一篇android View 繪制完成監(jiān)聽的實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09
詳解Android中使用Notification實現(xiàn)進(jìn)度通知欄(示例三)
這篇文章主要介紹了詳解Android中使用Notification實現(xiàn)進(jìn)度通知欄(示例三),具有一定的參考價值,有興趣的可以了解一下。2016-12-12
Android視頻/音頻緩存框架AndroidVideoCache(Okhttp)詳解
這篇文章主要為大家詳細(xì)介紹了Android視頻、音頻緩存框架AndroidVideoCache,實現(xiàn)邊下邊播功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-07-07
Android使用多線程進(jìn)行網(wǎng)絡(luò)聊天室通信
這篇文章主要為大家詳細(xì)介紹了Android使用多線程進(jìn)行網(wǎng)絡(luò)聊天室通信,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-10-10
Android仿百度谷歌搜索自動提示框AutoCompleteTextView簡單應(yīng)用示例
這篇文章主要介紹了Android仿百度谷歌搜索自動提示框AutoCompleteTextView簡單應(yīng)用,結(jié)合實例形式分析了AutoCompleteTextView Widget使用步驟與相關(guān)操作技巧,需要的朋友可以參考下2016-10-10

