`
BestUpon
  • 浏览: 284117 次
  • 性别: Icon_minigender_1
  • 来自: 兰州
社区版块
存档分类
最新评论

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();
	}
  • 大小: 4.9 KB
分享到:
评论
5 楼 mmh19890108 2013-08-11  
楼主什么时候在线啊 求份源码603411857@qq.com
4 楼 hljstardust2012 2013-01-25  
可否给发给例子哈,最近正在研究hljylq@163.com,谢谢了
3 楼 lxy189 2013-01-04  
这个demo可以发我吗?谢谢了,553308140@qq.com
2 楼 danpianji 2012-09-05  
Ptas_Tab_Bottom这个xml怎么没有啊
1 楼 bsand 2012-03-15  

相关推荐

Global site tag (gtag.js) - Google Analytics