Question

I am currently using Jake Wharton's ViewPagerIndicator with my adapter of fragments. Everything works perfectly fine when I have the indicator adjacent to my pager like he mentions.

However, I was hoping to put the indicator inside my Custom ActionBar view. However after setting the Indicator to

getActionBar.getCustomView.findViewById(R.id.indicator)

nothing happens.

Does the indicator HAVE to be adjacent to my pager? Is there a way to place it into a custom action bar view?

As far as I know, I haven't seen any S.O. questions about this yet.

--NOTE-- This has nothing to do with ActionBarSherlock!

Was it helpful?

Solution

Is there a way to place it into a custom action bar view?

Absolutely, you can place it in the ActionBar.

Here's an example using the UnderlinePageIndicator:

Custom layout

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <com.viewpagerindicator.UnderlinePageIndicator
        android:id="@+id/pager_indicator"
        android:layout_width="match_parent"
        android:layout_height="2dp" />

</FrameLayout>

Implementation

// Set up the PagerIndicator
final View abi = getLayoutInflater().inflate(R.layout.action_bar_indicator, null);
final UnderlinePageIndicator upi = (UnderlinePageIndicator) abi
        .findViewById(R.id.pager_indicator);
upi.setViewPager(yourViewPager);

// Set up the ActionBar
final ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
// Enable the custom display option and apply the layout
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(abi);

Results

Example

OTHER TIPS

You'll have to set the custom view first.

getActionBar().setCustomView(R.layout.custom_action_bar)

This layout would contain your ViewPagerIndicator widget.

Then grab a reference to the indicator widget, and bind it to the pager.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top