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實現(xiàn)的ListView分組布局改進示例
這篇文章主要介紹了Android實現(xiàn)的ListView分組布局改進的方法,結(jié)合實例形式分析了Android針對ListView的分組布局相關(guān)操作技巧,需要的朋友可以參考下2016-08-08Android源碼導(dǎo)入AndroidStudio或IntelliJ?IDEA的方法
這篇文章主要介紹了Android源碼導(dǎo)入AndroidStudio或IntelliJ?IDEA的方法,用idegen來生成針對AndroidStudio或IntelliJ?IDEA的Android系統(tǒng)源代碼工程配置文件,需要的朋友可以參考下2022-08-08Android編程簡單實現(xiàn)ImageView點擊時背景圖修改的方法
這篇文章主要介紹了Android編程簡單實現(xiàn)ImageView點擊時背景圖修改的方法,涉及Android針對背景圖相關(guān)屬性設(shè)置的操作技巧,需要的朋友可以參考下2015-12-12Android編程實現(xiàn)的微信支付功能詳解【附Demo源碼下載】
這篇文章主要介紹了Android編程實現(xiàn)的微信支付功能,結(jié)合實例形式詳細分析了Android微信支付功能的實現(xiàn)步驟與具體操作技巧,并附帶了Demo源碼供讀者下載參考,需要的朋友可以參考下2017-07-07