android 实现类似Iphone底部消息数量提示
16lz
2021-12-04
1.xml布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ptas_operation_bottom_bar" android:layout_width="fill_parent" android:layout_height="wrap_content"android:layout_alignParentBottom="true" android:gravity="center_vertical" android:orientation="horizontal" android:paddingLeft="0.6600001dip" android:paddingRight="0.6600001dip"><RadioGroup android:id="@+id/main_radio" style="@style/Ptas_Tab_Radio_Group_Bg" android:layout_gravity="bottom"><RadioButton android:id="@+id/radio_navigation" style="@style/Ptas_Tab_Bottom" android:layout_marginTop="2.0dip" android:text="文字一" /><RadioButton android:id="@+id/radio_vary" style="@style/Ptas_Tab_Bottom" android:layout_marginTop="2.0dip" android:text="文字一" /><RadioButton android:id="@+id/radio_doing" style="@style/Ptas_Tab_Bottom" android:layout_marginTop="2.0dip" android:text="文字一" /><RelativeLayout android:id="@+id/notice_re" style="@style/Ptas_Tab_Bottom_Notice"><RadioButton android:id="@+id/radio_notice" style="@style/Ptas_Tab_Bottom" android:layout_centerInParent="true" android:layout_marginTop="2.0dip" android:text="文字一" /><TextView android:id="@+id/notice_count_text" android:layout_width="28dip" android:layout_height="28dip" android:layout_alignParentRight="true" android:layout_alignParentTop="true"android:background="@drawable/notice_count" android:gravity="center" android:text="0" android:textSize="13dip" android:textStyle="bold" /></RelativeLayout><RadioButton android:id="@+id/radio_setting" style="@style/Ptas_Tab_Bottom" android:layout_marginTop="2.0dip" android:text="文字一" /></RadioGroup></LinearLayout>
2.代码控制切换GroupRadio
private void mainBtnGroupOnclick() {mainBtnGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {if (navigaionBtn.getId() == checkedId) {tabHost.setCurrentTab(1);} else if (varyBtn.getId() == checkedId) {tabHost.setCurrentTab(2);} else if (doingBtn.getId() == checkedId) {tabHost.setCurrentTab(3);} else if (settingBtn.getId() == checkedId) {tabHost.setCurrentTab(5);}if (checkedId != noticeBtn.getId()) {noticeBtn.setChecked(false);noticeBtn.setFocusableInTouchMode(false);}}});navigaionBtn.setOnClickListener(this);varyBtn.setOnClickListener(this);doingBtn.setOnClickListener(this);noticeBtn.setOnClickListener(this);settingBtn.setOnClickListener(this);}@Overridepublic void onClick(View view) {if (view.getId() == noticeBtn.getId()) {noticeBtn.setBackgroundResource(R.drawable.home_btn_bg_d);navigaionBtn.setChecked(false);doingBtn.setChecked(false);varyBtn.setChecked(false);settingBtn.setChecked(false);settingBtn.setFocusableInTouchMode(false);varyBtn.setFocusableInTouchMode(false);doingBtn.setFocusableInTouchMode(false);navigaionBtn.setFocusableInTouchMode(false);tabHost.setCurrentTab(4);} else {noticeBtn.setBackgroundColor(android.R.color.transparent);}}
3.更新数字
Handler myHandler = new Handler() {public void handleMessage(Message msg) {switch (msg.what) {case Main.NOTICE_COUNTER_MESSAGE_WHAT:int counter = msg.getData().getInt("counter", 0);if (counter == 0) {noticeCountText.setVisibility(View.GONE);} else {noticeCountText.setText("" + counter);noticeCountText.setVisibility(View.VISIBLE);}break;}super.handleMessage(msg);}};private void updateNoticeCounter() {new Thread(new Runnable() {@Overridepublic void run() {while (!Thread.currentThread().isInterrupted()) {Message message = new Message();message.what = Main.NOTICE_COUNTER_MESSAGE_WHAT;Bundle data = new Bundle();data.putInt("counter", NoticeHolder.getNoticeInfos().size());message.setData(data);myHandler.sendMessage(message);try {Thread.sleep(100);} catch (InterruptedException e) {Thread.currentThread().interrupt();}}}}).start();}
更多相关文章
- 关于文字颜色/图片背景---selector状态列表
- android 的C++代码都加 namespace android
- Android--通过关键字查找短消息数据库并将匹配的信息显示
- [Android] 代码实现按钮/图片自旋转(中心旋转)
- android 单元测试
- Android的Location功能代码
- Android(安卓)framwork 锁屏界面开发 笔记
- android studio多渠道号,多包名打包
- 页面跳转采用滑动效果