Configure FragmentTabHost set TabWidget at the bottom

I am currently trying to implement a FragmentTabHost for my project. I am still new to this snippet, but I found it very good in terms of reusing layouts etc., so I wanted to push it even further. Now I read the tutorials on how to create tabs with snippet, and I came to this guide:

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

Now this works fine, except that the tabWidget is on top of my layout, where I wanted it to be at the bottom. I found that I needed to configure tabWidget after all the tabs were initialized, so I tried to add these codes:

mTabWidget = (TabWidget) findViewById(android.R.id.tabs); mTabWidget.setBackgroundColor(Color.WHITE); mTabWidget.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE); mTabWidget.setGravity(Gravity.BOTTOM); 

Now this one already removes the separator and changes color, but obviously it won’t put my widget at the bottom of my layout. Now, how would I do that?

I also tried to edit the Tabhost XML file and just put the TabWidget after FrameLayout, but nothing happens. here 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> 
+6
source share
1 answer

I reference this link github example

This will be your layout:

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

For your custom tabs:

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

end edit

If you want to add drawable (selector):

 <?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> 
+13
source

Source: https://habr.com/ru/post/952806/


All Articles