saeid-xplod
saeid-xplod

Reputation: 33

How to use ActionBarSherlock, ViewPagerIndicator and SlidingMenu

how can I setup project dependencies for working with ActionBarSherlock, ViewPagerIndicator and SlidingMenu (in inteliij) ?

it's my setup:

And everything is ok. I want to add SlidingMenu (Note:ActionBarSherlock is a dependency to SlidingMenu) as a dependency to my project. how can I do that? [I think my problem is that I don't know how to setup all of dependencies in this situation]

EDIT: I want ViewPagerIndicator for this result :

OK

Upvotes: 3

Views: 3014

Answers (1)

dougcunha
dougcunha

Reputation: 1238

I can use (you need to add Android compatibility library):

public class MainActivity extends SlidingFragmentActivity  {
        private ViewPager viewPager;
        private RelativeLayout root;            
        @Override
        public void onCreate(Bundle savedState) {
                super.onCreate(savedState);
                root = (RelativeLayout) getLayoutInflater().inflate(R.layout.activity_main, null);
                setBehindContentView(root);

                (...)

                viewPager = (ViewPager) getLayoutInflater().inflate(R.layout.viewPager, null);
                setContentView(vPager);

                viewPager.setOnPageChangeListener(new OnPageChangeListener() {
                    @Override
                    public void onPageSelected(int id) {                                
                        switch (id) {
                        case 0:             
                            getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); //on first page, you can get slidingmenu by swipping the entire screen
                            break;               
                        default:
                            getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN); //on others page, you can get slidingmenu by swipping the half screen
                            break;
                        }                

                    }
                    @Override
                    public void onPageScrolled(int arg0, float arg1, int arg2) {

                    }
                    @Override
                    public void onPageScrollStateChanged(int arg0) {

                    }
                });
        }

}

on your FragmentPageAdapter, override

   @Override
    public CharSequence getPageTitle(int position) {
        return "your page title for position"
    }

-> activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/layoutFull"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#66ffffff"
    android:baselineAligned="true"
    android:orientation="vertical" >    

</RelativeLayout>

-> viewPager.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/viewPagert"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.v4.view.PagerTabStrip
        android:id="@+id/pager_title_strip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="#fff"
        android:paddingBottom="2dp"
        android:paddingTop="2dp"
        android:textColor="#000" />

</android.support.v4.view.ViewPager>

Upvotes: 2

Related Questions