我可以使用(需要添加Android兼容库):
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) {
}
});
}
}
在您的 FragmentPageAdapter 上,覆盖
@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>