当前位置: 代码迷 >> Iphone >> android 兑现类似Iphone底部消息数量提示
  详细解决方案

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

热度:21   发布时间:2016-04-25 06:30:36.0
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();	}
1 楼 bsand 2012-03-15  
  相关解决方案