다음은 탭 호스트를 만드는 방법입니다. 사용자가 탭을 클릭하면 탭을 가져 오는 것입니다. 문제는 태그 값 대신 null을 반환한다는 것입니다.FragmentTabHost는 탭의 태그를 얻을 때 null을 반환합니다.
tabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
tabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
tabHost.addTab(
tabHost.newTabSpec("home").setIndicator("",
getResources().getDrawable(R.drawable.meun_home)),
HomeFragment.class, null);
tabHost.addTab(
tabHost.newTabSpec("form").setIndicator("",
getResources().getDrawable(R.drawable.meun_register)),
FormFragment.class, null);
tabHost.addTab(
tabHost.newTabSpec("calculator").setIndicator("",
getResources().getDrawable(R.drawable.meun_calculator)),
CalculatorFragment.class, null);
tabHost.addTab(
tabHost.newTabSpec("news").setIndicator("",
getResources().getDrawable(R.drawable.meun_call)),
HomeFragment.class, null);
tabHost.getTabWidget().setDividerDrawable(
getResources().getDrawable(R.drawable.border));
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(getResources().getColor(android.R.color.transparent));
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.MATCH_PARENT, 1f);
tabHost.getTabWidget().getChildAt(i).setLayoutParams(params);
tabHost.getTabWidget().getChildAt(i).setPadding(0, 0, 0, 0);
tabHost.getTabWidget().getChildAt(i).setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
if(action == MotionEvent.ACTION_UP) {
Log.d("test1",""+v.getTag());
return true; // doesnt allow tab change
}
return false;
}
});
}
null을 반환하는 행 Log.d("test1",""+v.getTag());
을 찾을 수 있습니다. 어떤 예상하는 등 "집", "양식", ..... 덕분에 많은
감사 및 .newTabSpec 그것이 태그 또는 I가 참조 할 수있는 ID입니다 덧붙였다 무엇인가? – user782104
업데이트 해 주셔서 감사합니다! 그래서 newTabSpec을 얻을 수는 없지만 그 아이콘에 태그를 설정해야합니까? – user782104
완료. 덕분에 많이 – user782104