2011-07-13 71 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; 
    } 

,我想知道 - 這可能只是加入的代碼行現有的一塊,而不是另起爐竈一切都改變文本的位置和(或)背景?謝謝!

所以是:文本位置和自定義背景(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")); 
    } 

}