2013-08-30 16 views
6

Obecnie próbuję wdrożyć FragmentTabHost dla mojego projektu. Wciąż jestem nowy w tych fragmentach, ale uznałem, że jest to bardzo dobre pod względem ponownego wykorzystywania układów itp., Dlatego chciałem się do tego popchnąć. Teraz czytam tutoriale jak tworzyć zakładki z fragmentu i przyjechałem na tym tutorialu:Dostosuj zestaw FragmentTabHost TabWidget na dole

http://maxalley.wordpress.com/2013/05/18/android-creating-a-tab-layout-with-fragmenttabhost-and-fragments/

teraz to działa dobrze, poza tym, że tabWidget jest na szczycie mojej układ gdzie chciałem go być na dole. Uważam, że trzeba skonfigurować tabWidget po wszystkich zakładkach został zainicjowany więc starałem się dodać te kody:

mTabWidget = (TabWidget) findViewById(android.R.id.tabs); 

    mTabWidget.setBackgroundColor(Color.WHITE); 
    mTabWidget.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE); 
    mTabWidget.setGravity(Gravity.BOTTOM); 

Teraz to już wyeliminował jeden dzielnik i zmienia kolor, ale oczywiście nie będzie można umieścić moje widget w dolnej części mojego układu. Jak mam to zrobić?

Próbowałem także edytować plik Tabhost xml i po prostu umieścić TabWidget po FrameLayout, ale nic się nie dzieje. oto xml:

<android.support.v4.app.FragmentTabHost 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@android:id/tabhost" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

      <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical" > 

       <FrameLayout 
         android:id="@+id/tabFrameLayout" 
         android:layout_width="match_parent" 
         android:layout_height="0dp" 
         android:layout_weight="1" /> 

       <TabWidget 
         android:id="@android:id/tabs" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="0" 
         android:orientation="horizontal" 
         /> 

      </LinearLayout> 

     </android.support.v4.app.FragmentTabHost> 

Odpowiedz

13

muszę odnieść ten link github example

To będzie Twój układ:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <FrameLayout 
     android:id="@+id/realtabcontent" 
     android:layout_width="match_parent" 
     android:layout_height="0dip" 
     android:layout_weight="1" /> 

    <android.support.v4.app.FragmentTabHost 
     android:id="@android:id/tabhost" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="0dp" 
      android:layout_height="0dp" 
      android:layout_weight="0" /> 
    </android.support.v4.app.FragmentTabHost> 

</LinearLayout> 

dla własnych zakładek:

mTabHost.addTab(setIndicator(mTabHost.newTabSpec("Tab1"), 
         R.drawable.image1), 

    public TabSpec setIndicator(Context ctx,TabSpec spec, int resid) { 
     // TODO Auto-generated method stub 
     View v = LayoutInflater.from(ctx).inflate(R.layout.tabs_text, null); 
     v.setBackgroundResource(resid); 
     TextView text = (TextView) v.findViewById(R.id.tab_title); 
     text.setText(spec.getTag()); 
     return spec.setIndicator(v); 
    } 

Edit

//To set drawable to your perticular TAB 
mTabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.tab_login); 

koniec Edit

Jeśli chcesz dodać rozciągliwej (selektor):

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:drawable="@drawable/tab_compose_h" android:state_selected="true"/> 
    <item android:drawable="@drawable/tab_compose_h" android:state_pressed="true"/> 
    <item android:drawable="@drawable/tab_compose"/> 

</selector> 
+0

Obecnie sprawdzenie go. :) – KaHeL

+0

Cześć Gru, testowałem to i tak to działa! Ale mam jeden problem. TabDividers pokazuje i nie wiem, aby to wyłączyć. jak również nie mogę zmienić koloru kart. Jak mam to zrobić? – KaHeL

+0

I już to mam! :)) Dziękuję bardzo! – KaHeL