FragmentTabHost нижний TabWidget

Привет. Как я могу создать нижний TabWidget в FragmentTabHost? Мой xml выглядит следующим образом:

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

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

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

        <FrameLayout
            android:id="@+id/realtabcontent"
            android:layout_width="match_parent"
            android:layout_height="fill_parent" />
    </FrameLayout>

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

Но мой TabWidget все еще наверху.


person MaeSTRo    schedule 10.12.2012    source источник
comment
Обратите внимание, что нижние вкладки противоречат эстетике дизайна Android: developer.android.com/design /patterns/pure-android.html   -  person CommonsWare    schedule 10.12.2012
comment
Я знаю, но мне нужно создать нижнюю вкладку с фрагментами.   -  person MaeSTRo    schedule 11.12.2012
comment
возможный дубликат Android: вкладки внизу   -  person akshay    schedule 19.12.2013
comment
Уже нет. Google теперь благословил вкладки в нижней части экрана!   -  person Greg Ennis    schedule 22.03.2016


Ответы (1)


Я придумал это решение после шести часов работы над ним.

<?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>

Обновление:

Для реализации пользовательских вкладок:

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);
    }

Параметр находится как Drawable, как показано ниже:

<?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>

https://github.com/rameshkec85/BottomTabsFragmentTabHost

person Ramesh Akula    schedule 13.02.2013
comment
Хорошая работа +1, не могли бы вы объяснить поведение ?? куда делся TabWidget!! - person Muhammad Babar; 21.05.2013
comment
Там FragmentTabHost просто панель вкладок и управляет фрагментом переключателя ??? если я хочу установить фон для панели вкладок, просто добавьте android:background=@drawable/test в раздел android.support.v4.app.FragmentTabHost в xml?? - person Mejonzhan; 23.05.2013
comment
Как я могу удалить вкладки с помощью FragmentTabHost - person moDev; 12.07.2013
comment
@Рамеш Спасибо. Как я могу изменить цвет фона вкладки при нажатии на вкладку?? Есть идеи - person moDev; 16.07.2013
comment
Работает очень хорошо. Но я не уверен, для чего предназначен второй FrameLayout (тот, что внутри FragmentTabHost). Вкладки работают без него. - person evanill80; 18.10.2016