2012-08-07 147 views
0

我試圖將選項卡放在屏幕的底部,並讓每個選項卡顯示不同的活動。在屏幕底部有標籤的Android?

但是,從我讀過的,你只能在手機上使用3.0+。

當我知道的大多數手機都在2.3左右時,這看起來有些荒謬。

任何人有任何想法?

+0

底部選項卡是iOS設計模式。他們可以在Android上感覺很外國:http://developer.android.com/design/patterns/pure-android.html – Krylez 2012-08-07 03:48:37

+0

參考這個http://stackoverflow.com/questions/2395661/android-tabs-at-the-底部 – KMI 2012-08-07 04:28:57

+0

只是不,不是真的,不要。 – 2012-08-07 05:31:43

回答

0

您可以通過底部的碎片和一組按鈕來實現最佳效果。

所以當點擊一個按鈕時,無論用戶點擊了什麼,都可以在主要內容區域進行片段轉換。

這就是說,底部的標籤在Android上是不好的形式。

+0

只是做了一些片段閱讀......可以在版本<3.0的手機上使用它們嗎? – droider 2012-08-07 03:08:48

+0

是的,使用支持庫jar,這有支持回到1.6。 – 2012-08-07 03:18:59

1

這可以使用了Android常用的標籤,只是你需要做的就是添加在xml.I一些額外的代碼希望這段代碼可以幫助你得到它完成實現...

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

> 

    <RelativeLayout 
     android:id="@+id/LinearLayout01" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent" 
      android:layout_above="@android:id/tabs"> 
     </FrameLayout> 

     <TabWidget 
      android:id="@android:id/tabs" 
      style="@style/customtab" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 

      > 
     </TabWidget> 
    </RelativeLayout> 

</TabHost> 

風格在這裏@風格/自定義標籤

<style name="customtab" parent="@android:style/Widget.TabWidget"> 
      <item name="android:tabStripEnabled">false</item> 
      <item name="android:tabStripLeft">@null</item> 
      <item name="android:tabStripRight">@null</item> 
     </style> 
0

下面的標籤欄使用下面的XML代碼。

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     android:padding="3dp" > 

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

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

</TabHost> 

並使用下面的java代碼。

public class MainActivity extends TabActivity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

       setContentView(R.layout.tab_screen); 
     TabHost tabHost = getTabHost(); 

     tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Home", getResources().getDrawable(R.drawable.home)).setContent(new Intent(this, HomeActivity.class))); 

     tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Second", getResources().getDrawable(R.drawable.invoice)).setContent(new Intent(this, SecondActivity.class))); 

     tabHost.setCurrentTab(0); 
    } 
}