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

阅读更多

1.xml布局

 



	

		

		

		

		
			
			
		
		
	

 

 

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();
	}
  • android 实现类似Iphone底部消息数量提示_第1张图片
  • 大小: 4.9 KB
  • 查看图片附件

你可能感兴趣的:(android,仿,Iphone,android,仿苹果,底部导航栏,消息提示)