1
TabActivity를 확장하는 MainActivity가있는 앱이 있습니다 (사용되지 않지만 전체 앱을 변경하기에는 너무 많음).선택한 탭에 따라 탭 색상이 변경됩니다.
이TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
TabSpec secondTabSpec = tabHost.newTabSpec("tid2");
TabSpec thirdTabSpec = tabHost.newTabSpec("tid3");
firstTabSpec.setIndicator("tab1").setContent(
new Intent(this, tab1.class));
secondTabSpec.setIndicator("tab2").setContent(
new Intent(this, tab2.class));
thirdTabSpec.setIndicator("tab3").setContent(
new Intent(this, tab3.class));
/* Add tabSpec to the TabHost to display. */
tabHost.addTab(firstTabSpec);
tabHost.addTab(secondTabSpec);
tabHost.addTab(thirdTabSpec);
//Changing the tabs text color on the tabs
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
TextView tv = (TextView) tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
tv.setTextColor(Color.parseColor("#ffffff"));
}
// remove divider
tabHost.getTabWidget().setDividerDrawable(null);
tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#90a4ae"));
tabHost.getTabWidget().getChildAt(1).setBackgroundColor(Color.parseColor("#607d8b"));
tabHost.getTabWidget().getChildAt(2).setBackgroundColor(Color.parseColor("#607d8b"));
그래서 내 코드는 3 개 가지 활동을 연결하는 3 개의 탭을 만들고 탭의 색상을 설정합니다
그래서 내 응용 프로그램에서이 같은 3 개의 탭을 만들 tabhost를 사용합니다. 첫 번째 탭은 다른 두 가지 색상과 다른 색상을 먼저로드합니다.어떤 색상이 선택되었는지에 따라 탭의 색상을 변경하고 싶습니다. 그래서 두 번째 탭을 누르면 첫 번째 # 607d8b 색상을 얻고 두 번째 탭은 # 90a4ae를 얻고 싶습니다. 세 번째와 동일합니다.
OnTabChangeListener를 구현하려고 시도했지만 작동하지 못했습니다. 각로드 탭 활동 내부 변경된 색상
tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#90a4ae"));
tabHost.getTabWidget().getChildAt(1).setBackgroundColor(Color.parseColor("#607d8b"));
tabHost.getTabWidget().getChildAt(2).setBackgroundColor(Color.parseColor("#607d8b"));
하지만 예상대로이 MainActivity에 정의되어 있기 때문에 그것이 (tabhost 해결할 수없는 오류가 발생
고맙습니다 : 이로했습니다. 부끄럽지 않고 매력적이었습니다. 좋아하는 색을 고쳐서 이제는 완벽합니다. – duk3r
언제나 환영합니다. –