I decided to use a ViewPager
in my application and everything is working fine.
I Know that I want to use a PagerTitleStrip
in my ViewPager
, but I've failed to find any info on how to do it...
The one and only page (sic!!) I found on this class is http://developer.android.com/reference/android/support/v4/view/PagerTitleStrip.html
So it seems I just need to add the PagerTitleStrip
within my ViewPager
layout, but I don't see anything new on my activity...
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.PagerTitleStrip
android:id="@+id/pagerTitleStrip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
</android.support.v4.view.ViewPager>
Does anyone know how to use it?
Edited:
Sorry it works when implementing the getPageTitle
method in the ViewPagerAdapter
... but I don't want any text displayed, just a small cursor to show the position of the current View compared to the previous and next ones...
I'm not sure what causing error in your case but this is how I use it, in your layout you should insert following code in your layout:
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" >
<android.support.v4.view.PagerTitleStrip
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top" />
</android.support.v4.view.ViewPager>
Then you should add the following code in your PageAdapter:
@Override
public CharSequence getPageTitle (int position) {
return "Your static title";
}
That's pretty it.
I had this issue too where the PagerTitleStrip was not visible. The answers above did not help. The problem was that I followed the example on http://developer.android.com/reference/android/support/v4/view/ViewPager.html.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mViewPager = new ViewPager(this);
mViewPager.setId(R.id.pager);
setContentView(mViewPager);
The code above shows the view pager but not the PagerTitleStrip.
I changed the code to
protected void onCreate(Bundle savedInstanceData) {
super.onCreate(savedInstanceData);
setTitle(R.string.my_title);
setContentView(R.layout.my_pager);
viewPager = (ViewPager)findViewById(R.id.pager);
res/layout/my_pager.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v4.view.PagerTitleStrip
android:id="@+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#33b5e5"
android:textColor="#fff"
android:paddingTop="4dp"
android:paddingBottom="4dp" />
</android.support.v4.view.ViewPager>
I was also able to be backward compatible to API 8 by removing all the code in the ViewPager (javadoc page) example to manipulate the ActionBar and ActionBar.Tab.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With