2011-07-13 3 views
0

簡単な質問(おそらく)。それだけで何度も繰り返し、すべてを開始していない、既存の作品へのコードの行を追加することによって、テキストの位置と(または)背景を変更することが可能である -android - tabs:カスタムbgの色とテキストの位置

intent = new Intent().setClass(this, About.class); 
    spec = tabHost.newTabSpec("albums").setIndicator("About") 
        .setContent(intent); 
    tabHost.addTab(spec); 
    for (int i = 0; i < tabHost.getTabWidget().getTabCount(); i++) { 
     tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 50; 
    } 

と私は思っていた:私はタブのこのデフォルトのGoogleのチュートリアルのコードを持っています?ありがとう!

だから:テキストの位置とカスタム背景(html色)。どうすればいいのですか?ありがとう!

P.S他のチュートリアルへのリンクをドロップしないでください。それらを理解するのはちょっと難しいです。 :/

答えて

0

私が探していたコードが見つかりました。私のTabs.javaアクティビティの完全なコードは次のとおりです。

package com.xjcdi.name; 

import com.xjcdi.exploringvilnius.R; 

public class Tabs extends TabActivity implements OnTabChangeListener { 

    TabHost tabHost; 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.tabs); 

     tabHost = (TabHost)findViewById(android.R.id.tabhost); 
     tabHost.setOnTabChangedListener(this); 

     Resources res = getResources(); // Resource object to get drawables 
     TabHost tabHost = getTabHost(); // The activity TabHost 
     TabHost.TabSpec spec; // Reusable 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, Places.class); 

     // Initialize a TabSpec for each tab and add it to the TabHost 
     spec = tabHost.newTabSpec("artists").setIndicator("Places") 
         .setContent(intent); 
     tabHost.addTab(spec); 
     for (int i = 0; i < tabHost.getTabWidget().getTabCount(); i++) { 
      tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 50; 
     } 
     for(int i=0;i<tabHost.getTabWidget().getChildCount();i++) 



     // Do the same for the other tabs 
     intent = new Intent().setClass(this, About.class); 
     spec = tabHost.newTabSpec("albums").setIndicator("About") 
         .setContent(intent); 
     tabHost.addTab(spec); 
     for (int i = 1; i < tabHost.getTabWidget().getTabCount(); i++) { 
      tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 50; 
     } 

     intent = new Intent().setClass(this, Artistai.class); 
     spec = tabHost.newTabSpec("songs").setIndicator("Map") 
         .setContent(intent); 
     tabHost.addTab(spec); 
     for (int i = 2; i < tabHost.getTabWidget().getTabCount(); i++) { 
      tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 50; 
     } 

     intent = new Intent().setClass(this, Map.class); 
     spec = tabHost.newTabSpec("songs").setIndicator("History") 
         .setContent(intent); 
     tabHost.addTab(spec); 
     for (int i = 3; i < tabHost.getTabWidget().getTabCount(); i++) { 
      tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 50; 
     } 



     tabHost.setCurrentTab(0); 
    } 

    @Override 
    public void onTabChanged(String tabId) { 
     // TODO Auto-generated method stub 
     for(int i=0;i<tabHost.getTabWidget().getChildCount();i++) 
     { 
      tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#000000")); 
     } 

     tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#c1902d")); 
    } 

}