android 实现类似Iphone底部消息数量提示

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() {
			@Override
			public 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);

	}

	@Override
	public 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() {
			@Override
			public 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();
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值