wbk727
wbk727

Reputation: 8408

Android Sliding Tabs - modifying sample project

I am trying to create a sliding tabs app like the one in the screenshot below although due to the lack of samples available, this one is the closest I could find for what I want to achieve.

I would be very grateful if anybody could help me with following:

  1. Which Java code needs to be removed in order to safely get rid of the colour picker at the bottom + what codes needs to replace it so that I can use a hex colour of my choice for the Action bar, Indicator colour, Tab titles, Tab backgrounds and Tab separators.
  2. Which code (Java and/or XML) needs to change so that I can use XML fragment files of my own rather than these 'cards'.

All help would be very much appreciated as there is literally no sample project out there that does what I want to achieve.

The link to the sample project that I intend to modify is below.

LINK: astuetz/PagerSlidingTabStrip · GitHub

Sliding tabs goal

Tabs

tabs

slidingTabs & my_tab_text_view

tabs n text

Upvotes: 0

Views: 1249

Answers (1)

royB
royB

Reputation: 12977

well for fragments of your own did you have a look at ViewPager? http://developer.android.com/training/animation/screen-slide.html

Also have a look at android sample code: https://developer.android.com/samples/SlidingTabsBasic/index.html

for controlling the actionBar: have a look at the new ToolBar api https://chris.banes.me/2014/10/17/appcompat-v21/

after that if you still have questions you are welcome to ask

 slidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);
 slidingTabLayout.setDividerColors(getResources().getColor(android.R.color.transparent));
 slidingTabLayout.setSelectedIndicatorColors(getResources().getColor(android.R.color.white));

add this method to SlidingTabLayout

public class SlidingTabLayout extends HorizontalScrollView {



    /**
    * #####################Add THIS METHOD ############
    *
    * @param layoutResId Layout id to be inflated
    * @param textViewId  id of the {@link TextView} in the inflated view
    */
   public void setCustomTabView (int layoutResId, int textViewId) {
       mTabViewLayoutId = layoutResId;
       mTabViewTextViewId = textViewId;
   }
...
}

from your activity:

public void onCreate(){
    slidingTabs.setCustomTabView(0, R.layout.my_tab_text_view)
}

where my_tab_text_view is a layout file:

<TextView

          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_weight="1"/>

just make sure that width is 0 and weight is 1

Upvotes: 1

Related Questions