// 탭 설정
tabHost = (TabHost) findViewById(R.id.tab_host);
tabHost.setup(getLocalActivityManager());
TabHost.TabSpec spec;
CustomTabBadge mTabWidget1 = new CustomTabBadge(this);
mTabWidget1.setImage(getResources().getDrawable(R.drawable.tab_photo_indicator));
mTabWidget1.setCount(0);
Intent intent1 = new Intent(this, PhotoMeetGroup.class);
spec = tabHost.newTabSpec("메뉴").setIndicator(mTabWidget1).setContent(intent1);
tabHost.addTab(spec); // Tab 등록
#########################################################
public class CustomTabBadge extends FrameLayout {
Context mContext;
TextView mTv; // 숫자 입력
ImageView mIv;
public CustomTabBadge(Context context) {
super(context);
mContext = context;
init();
}
public CustomTabBadge(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
init();
}
public CustomTabBadge(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mContext = context;
init();
}
public void init() {
LayoutInflater.from(mContext).inflate(R.layout.custom_tab_badge, this, true);
mIv = (ImageView) findViewById(R.id.iv);
mTv = (TextView) findViewById(R.id.tv);
}
public void setCount(String str) {
setCount("" + str);
}
public void setCount(int i) {
if (i != 0) {
mTv.setVisibility(View.VISIBLE);
mTv.setText("" + i);
} else {
mTv.setVisibility(View.GONE);
}
}
public void setImage(Drawable d) {
mIv.setImageDrawable(d);
}
}
############################################
badge를 표시할 xml
custom_tab_badge.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/iv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:scaleType="fitXY" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top|center_horizontal" >
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dip"
android:background="@drawable/icon_new"
android:gravity="center"
android:singleLine="true"
android:textColor="@android:color/black"
android:textSize="1dp" />
</LinearLayout>
</RelativeLayout>
이 외에는 일반 tab 사용과 동일
'자료' 카테고리의 다른 글
바이너리 XML 을 읽을 수 있는 XML 로 변환하는 방법 (0) | 2012.10.16 |
---|---|
안드로이드 버전별 특징ppt (0) | 2012.10.16 |
SMS Receiver (1) | 2012.09.03 |
보안서버 웹페이지를 웹뷰에서 보기 (0) | 2012.08.31 |
뒤로가기 두번으로 앱 종료 하기 (1) | 2012.08.31 |