2013-10-10 2 views
0

4 개의 탭 탭이있는 Android 탭에서 간단한 탭 앱을 실행하려고합니다. 내 문제는 내가 아이콘 표시를 표시 할 때, 그냥 내가 tabhost에 당김 및 표시 텍스트를 표시하려면, 텍스트 만 표시를 표시한다는 것입니다,이 내 코드입니다 : 내가 사용하는 경우android : 탭 호스트에 표시기 텍스트와 드로어 블을 표시 할 수 없습니다.

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     //hide title bar 
       BasicDisplaySettings.toggleTaskBar(SimasCardMainActivity.this, false); 
       //show status bar 
       BasicDisplaySettings.toggleStatusBar(SimasCardMainActivity.this, true); 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.simascard); 

     Resources res = getResources(); // Resource object to get Drawables 
     TabHost tabHost = getTabHost(); // The activity TabHost 
     TabHost.TabSpec spec; // Resusable TabSpec for each tab 
     Intent intent; // Reusable Intent for each tab 

     // Create an Intent to launch an Activity for the tab (to be reused) 
     intent = new Intent().setClass(this, TerbaruSimasCard.class); 
     spec = tabHost.newTabSpec("Terbaru").setIndicator("Terbaru", 
        res.getDrawable(R.drawable.menu_terbaru)) 
        .setContent(intent); 
     tabHost.addTab(spec); 

     intent = new Intent().setClass(this, MerchantSimasCard.class); 
     spec = tabHost.newTabSpec("Merchant").setIndicator("Merchant", 
        res.getDrawable(R.drawable.menu_merchant)) 
        .setContent(intent); 
     tabHost.addTab(spec); 

     intent = new Intent().setClass(this, TentangSimasCard.class); 
     spec = tabHost.newTabSpec("Tentang").setIndicator("Tentang", 
        res.getDrawable(R.drawable.menu_tentang)) 
        .setContent(intent); 
     tabHost.addTab(spec); 

     intent = new Intent().setClass(this, FaqSimasCard.class); 
     spec = tabHost.newTabSpec("FAQ").setIndicator("FAQ", 
        res.getDrawable(R.drawable.menu_faq)) 
        .setContent(intent); 
     tabHost.addTab(spec); 


     for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++){ 
      tabHost.getTabWidget().getChildAt(i).setPadding(0,0,0,0); 
      tabHost.getTabWidget().getChildTabViewAt(i).setBackgroundDrawable(null); 
     } 
     tabHost.setCurrentTab(0); 
    } 

// @Override 
    public void onBackPressed() { 
    finish(); 
    } 

spec = tabHost.newTabSpec("Tentang").setIndicator("", 
         res.getDrawable(R.drawable.menu_tentang)) 
         .setContent(intent); 

아이콘이 표시되지만, setIndicator 같은 텍스트를 추가 할 때 setIndicator("Tentang")과 같이 표시기 텍스트 만 tabhost에 표시됩니다. 내 코드에 문제가있는 곳을 모르지만 탭 높이를 늘리려고했습니다. ,하지만 그것은 작동하지 않습니다, 나는 누군가가 내 문제를 해결하는 데 도움이되기를 바랍니다. 당신은

답변

0

tabHost.getTabWidget().getChildTabViewAt(i).setBackgroundDrawable(null);

를 제거하고 난 이런 식으로 일을 한

tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.menu_tentang); 

로 교체하며

Resources ressources = getResources(); 
    TabHost tabHost = getTabHost(); 

    Intent addfriend = new Intent().setClass(this, yourclass1.class); 
    Intent mailfriend = new Intent().setClass(this, yourclass2.class); 
    tabHost.addTab(tabHost.newTabSpec("child1").setIndicator("your tag",getResources().getDrawable(R.drawable.youpng)).setContent(addfriend)); 
    tabHost.addTab(tabHost.newTabSpec("child1").setIndicator("your tag",getResources().getDrawable(R.drawable.yourpng)).setContent(mailfriend)); 



    tabHost.getTabWidget().getChildAt(0).setBackgroundColor(getResources().getColor(R.color.anycolor)); 
    tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.yourpng); 

    tabHost.getTabWidget().getChildAt(1).setBackgroundColor(getResources().getColor(R.color.anycolor)); 
    tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.youpng); 
+0

심각하게 잘 작동 감사? 나는 그것이 작동 할 것이라고 생각하지 않는다 .... –

+0

@AoyamaNanami 내 편집을 보아라. –