I need to make my application with this appearance (icon and text): https://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0B6Okdz75tqQsbHJuWi04N0ZIc0E/components_tabs_usage_mobile7.png
But so far I can only leave it like this: http://i.imgur.com/npz0eRJ.png
How can I fix this?
Follow my xml tabs:
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
android: layout_width = "match_parent"
android: layout_height = "match_parent"
android: gravity = "center">
<ImageView
android: id = "@ + id / imgTab"
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
/>
<TextView
android: TEXTSIZE = "14sp"
android: textColor = "@ android: color / white"
android: id = "@ + id / tv_tab"
android: layout_width = "wrap_content"
android: layout_height = "wrap_content" />
</ LinearLayout>
Method in the fragment (Tab):
public CharSequence getPageTitle (int position) {
Drawable tab = mContext.getResources () getDrawable (icons [position]).;
tab.setBounds (0, 0, heightIcon, heightIcon);
ImageSpan ImageSpan is = new (tab);
SpannableString sp = new SpannableString (titles [position]);
sp.setSpan (s, sp.length () - 1, sp.length (), 0);
return sp;
I tried to follow Need to center-align a single portion of text in a TextView but it did not work for me :(
Can anyone help me please?
Using the default Tabbed Activity from android studio, just add the following:
See my answer Here and follow it properly.
A little change here will do the trick:
in place of the "hello" use your title.
Hope it will help.
You can achieve your task with the following very easily. Firstly create new XML under Layout Folder. Give it name [custom_tab_view] then paste the below code.
And now went to your ViewPageAdapter and Replace your Function [CharSequence] with below code.
and in the MainActivity under OnCreate put this line if it is not already there.