Does someone know how to use PagerTitleStrip in Android

前端 未结 3 1329
我在风中等你
我在风中等你 2021-02-04 01:33

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

3条回答
  •  孤街浪徒
    2021-02-04 02:14

    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:

     
     
    
        
    
     
    

    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.

提交回复
热议问题