1. java
package com.ahikuya; import android.app.TabActivity; import android.content.Intent; import android.os.Bundle; import android.widget.ImageView; import android.widget.TabHost; import android.widget.TabHost.OnTabChangeListener; public class LayoutTab extends TabActivity implements OnTabChangeListener { /** Called when the activity is first created. */ TabHost tabHost; Intent It; ImageView iv; int aTabIcon[] = {R.drawable.tabhost_home,R.drawable.tabhost_around,R.drawable.tabhost_premium,R.drawable.tabhost_my,R.drawable.tabhost_set}; int aTabOver[] = {R.drawable.tabhost_home_ov,R.drawable.tabhost_around_ov,R.drawable.tabhost_premium_ov,R.drawable.tabhost_my_ov,R.drawable.tabhost_set_ov}; int aTabText[] = {R.string.tab1_title,R.string.tab2_title,R.string.tab3_title,R.string.tab4_title,R.string.tab5_title}; String aTabSpec[] = {"Tab01","Tab02","Tab03","Tab04","Tab05"}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_tab); tabHost = getTabHost(); for(int i = 0; i < 5; i++) { switch(i) { case 0: It = new Intent(this, tab1Activity.class); break; case 1: It = new Intent(this, tab2Activity.class); break; case 2: It = new Intent(this, tab3Activity.class); break; case 3: It = new Intent(this, tab4Activity.class); break; case 4: It = new Intent(this, tab5Activity.class); break; } // tabHost 생성 tabHost.addTab( tabHost.newTabSpec(aTabSpec[i]) .setIndicator(getResources().getString(aTabText[i]), getResources().getDrawable(aTabIcon[i])) .setContent(It) ); // TabHost 높이 tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 100; // TabHost 배경 tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tabhost_bg); } // debug Tab tabHost.setCurrentTab(0); // Look at Tab Change tabHost.setOnTabChangedListener(this); } // 선택된 Tab에 대한 처리 @Override public void onTabChanged(String tabId ) { /** * debug String strTabName; strTabName = "onTabChanged : " + tabId; Toast.makeText(this, strTabName, 1000).show(); */ // 이미지 초기화 for(int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) { iv = (ImageView) tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.icon); iv.setImageDrawable(getResources().getDrawable(aTabIcon[i])); /** * 배경색 초기화 tabHost.getTabWidget().getChildAt(i).setBackgroundColor(R.color.black); */ } //선택된 탭의 스타일 처리 for(int i = 0; i < aTabSpec.length; i++) { if(aTabSpec[i] == tabId) { iv = (ImageView) tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).findViewById(android.R.id.icon); iv.setImageDrawable(getResources().getDrawable(aTabOver[i])); /** * 글자색 변경 TextView tv = (TextView) tabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title); tv.setTextColor(Color.parseColor("#000000")); */ /** * 배경색 변경 tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#000011")); */ break; } } } }
2. xml
'개발 > 안드로이드' 카테고리의 다른 글
[안드로이드] 네트워크 상태 변화 감지하기(BroadcastReceiver 사용) (0) | 2012.07.19 |
---|---|
[android] AES 이용한 암호화/복호화 예제 (0) | 2012.07.17 |
LayoutInflater 의 다양한 코드 (0) | 2012.07.13 |
Android Layout별 속성 정리 (0) | 2012.07.11 |
안드로이드 기기별 해상도 & 치수 (0) | 2012.07.11 |