2011-11-08 26 views
5

當標籤被選定曲線按鈕必須在特定的標籤可見,另一個爲共用如何獲得的TabBar enter image description here如何得到這個的TabBar

以下設計。

我想添加一個固定的背景顏色是紅色的,我想把曲線和沒有曲線的圖像的按鈕。但我想知道它是否得到固定的所有Android設備,因爲笏是按鈕的高度和寬度?如何設置固定高度和寬度的標籤欄....

+0

+1對於有用的問題的問。 – Praveenkumar

+0

你在這裏談論什麼:TabWidget或ActionBar? –

回答

2

我用一個簡單的方法發現如下

要在使用TabBar底部獲得紅線我有標籤下添加一個view如下

<TabHost 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:id="@+id/linearLayout1" 
     android:layout_height="fill_parent" 
     android:orientation="vertical"> 

     <TabWidget 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:id="@android:id/tabs" 
      android:layout_alignParentBottom="true" 
      android:layout_weight="0"> 
     </TabWidget> 

     <View android:layout_width="fill_parent" android:layout_height="4dip" android:background="#ff0000" /> 

     <FrameLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:id="@android:id/tabcontent" 
      android:layout_weight="1"> 
     </FrameLayout> 

    </LinearLayout> 
</TabHost> 

然後我的TabBar類是如下

public class CustomTabActivity extends TabActivity 
{ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.tabbar); 

     addTab1(FirstTab.class); 
     addTab2(SecondTab.class); 
     addTab3(FirstTab.class); 
     addTab4(SecondTab.class); 
    } 

    private void addTab1(Class<?> c) 
    { 
     TabHost tabHost = getTabHost(); 
     Intent intent = new Intent(this, c); 
     TabHost.TabSpec spec = tabHost.newTabSpec("tab"); 

     View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator1, getTabWidget(), false); 
     ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon1); 

     spec.setIndicator(tabIndicator); 
     spec.setContent(intent); 
     tabHost.addTab(spec); 
    } 
} 

我tab_indicator佈局如下

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="0dip" 
    android:layout_height="55dip"  
    android:layout_weight="1" 
    android:orientation="vertical" 
    android:padding="5dp"> 

    <ImageView android:id="@+id/icon1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:background="@drawable/tab1">  
    </ImageView> 
</RelativeLayout> 

在抽拉所述TAB1是一個選擇XML文件作爲

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item android:state_focused="false" android:state_selected="false" 
     android:state_pressed="false" android:drawable="@drawable/home" /> 
    <item android:state_focused="false" android:state_selected="true" 
     android:state_pressed="false" android:drawable="@drawable/home_select_btn" /> 

</selector> 

在這裏如下我已經加入所選擇的圖像與一個彎曲的和未選擇圖像而不彎曲,即我想顯示。

這種方式似乎很長,但我覺得它是我需要的相同設計。

0

也許this example將對您有用。 Google+應用程序具有相同的導航功能。