use of android.support.v4.view.ViewPager in project Android-SpinKit by ybq.
the class DetailActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
viewPager.setOffscreenPageLimit(0);
viewPager.setAdapter(new PagerAdapter() {
@Override
public int getCount() {
return Style.values().length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
@SuppressLint("InflateParams") View view = LayoutInflater.from(container.getContext()).inflate(R.layout.item_pager, null);
SpinKitView spinKitView = (SpinKitView) view.findViewById(R.id.spin_kit);
TextView name = (TextView) view.findViewById(R.id.name);
Style style = Style.values()[position];
name.setText(style.name());
Sprite drawable = SpriteFactory.create(style);
spinKitView.setIndeterminateDrawable(drawable);
container.addView(view);
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
});
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
int color = (int) ArgbEvaluator.getInstance().evaluate(positionOffset, colors[position % colors.length], colors[(position + 1) % colors.length]);
getWindow().getDecorView().setBackgroundColor(color);
}
@Override
public void onPageSelected(int position) {
getWindow().getDecorView().setBackgroundColor(colors[position % colors.length]);
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
viewPager.setCurrentItem(getIntent().getIntExtra("position", 0));
}
use of android.support.v4.view.ViewPager in project CloudReader by youlookwhat.
the class MainActivity method initContentFragment.
private void initContentFragment() {
ArrayList<Fragment> mFragmentList = new ArrayList<>();
mFragmentList.add(new GankFragment());
mFragmentList.add(new OneFragment());
mFragmentList.add(new BookFragment());
// 注意使用的是:getSupportFragmentManager
MyFragmentPagerAdapter adapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), mFragmentList);
vpContent.setAdapter(adapter);
// 设置ViewPager最大缓存的页面个数(cpu消耗少)
vpContent.setOffscreenPageLimit(2);
vpContent.addOnPageChangeListener(this);
mBinding.include.ivTitleGank.setSelected(true);
vpContent.setCurrentItem(0);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
//去除默认Title显示
actionBar.setDisplayShowTitleEnabled(false);
}
}
use of android.support.v4.view.ViewPager in project Android-skin-support by ximsfei.
the class SlidingTabActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sliding_tab);
for (String title : mTitles) {
mFragments.add(SimpleCardFragment.getInstance(title));
}
View decorView = getWindow().getDecorView();
ViewPager vp = ViewFindUtils.find(decorView, R.id.vp);
mAdapter = new MyPagerAdapter(getSupportFragmentManager());
vp.setAdapter(mAdapter);
/** 默认 */
SlidingTabLayout tabLayout_1 = ViewFindUtils.find(decorView, R.id.tl_1);
/**自定义部分属性*/
SlidingTabLayout tabLayout_2 = ViewFindUtils.find(decorView, R.id.tl_2);
/** 字体加粗,大写 */
SlidingTabLayout tabLayout_3 = ViewFindUtils.find(decorView, R.id.tl_3);
/** tab固定宽度 */
SlidingTabLayout tabLayout_4 = ViewFindUtils.find(decorView, R.id.tl_4);
/** indicator固定宽度 */
SlidingTabLayout tabLayout_5 = ViewFindUtils.find(decorView, R.id.tl_5);
/** indicator圆 */
SlidingTabLayout tabLayout_6 = ViewFindUtils.find(decorView, R.id.tl_6);
/** indicator矩形圆角 */
final SlidingTabLayout tabLayout_7 = ViewFindUtils.find(decorView, R.id.tl_7);
/** indicator三角形 */
SlidingTabLayout tabLayout_8 = ViewFindUtils.find(decorView, R.id.tl_8);
/** indicator圆角色块 */
SlidingTabLayout tabLayout_9 = ViewFindUtils.find(decorView, R.id.tl_9);
/** indicator圆角色块 */
SlidingTabLayout tabLayout_10 = ViewFindUtils.find(decorView, R.id.tl_10);
tabLayout_1.setViewPager(vp);
tabLayout_2.setViewPager(vp);
tabLayout_2.setOnTabSelectListener(this);
tabLayout_3.setViewPager(vp);
tabLayout_4.setViewPager(vp);
tabLayout_5.setViewPager(vp);
tabLayout_6.setViewPager(vp);
tabLayout_7.setViewPager(vp, mTitles);
tabLayout_8.setViewPager(vp, mTitles, this, mFragments);
tabLayout_9.setViewPager(vp);
tabLayout_10.setViewPager(vp);
vp.setCurrentItem(4);
tabLayout_1.showDot(4);
MsgView rtv_1_4 = tabLayout_1.getMsgView(4);
if (rtv_1_4 != null) {
if (rtv_1_4 instanceof SkinMsgView) {
((SkinMsgView) rtv_1_4).setBackgroundColorResource(R.color.msg_background_color);
((SkinMsgView) rtv_1_4).setStrokeColorResource(R.color.msg_stroke_color);
} else {
rtv_1_4.setBackgroundColor(Color.parseColor("#6D8FB0"));
}
}
tabLayout_3.showDot(4);
tabLayout_2.showDot(4);
tabLayout_2.showMsg(3, 5);
tabLayout_2.setMsgMargin(3, 0, 10);
MsgView rtv_2_3 = tabLayout_2.getMsgView(3);
if (rtv_2_3 != null) {
if (rtv_2_3 instanceof SkinMsgView) {
((SkinMsgView) rtv_2_3).setBackgroundColorResource(R.color.msg_background_color);
((SkinMsgView) rtv_2_3).setStrokeColorResource(R.color.msg_stroke_color);
} else {
rtv_2_3.setBackgroundColor(Color.parseColor("#6D8FB0"));
}
}
tabLayout_2.showMsg(5, 5);
tabLayout_2.setMsgMargin(5, 0, 10);
// tabLayout_7.setOnTabSelectListener(new OnTabSelectListener() {
// @Override
// public void onTabSelect(int position) {
// Toast.makeText(mContext, "onTabSelect&position--->" + position, Toast.LENGTH_SHORT).show();
// }
//
// @Override
// public void onTabReselect(int position) {
// mFragments.add(SimpleCardFragment.getInstance("后端"));
// mAdapter.notifyDataSetChanged();
// tabLayout_7.addNewTab("后端");
// }
// });
}
use of android.support.v4.view.ViewPager in project Android-skin-support by ximsfei.
the class MainActivity method configFragments.
private void configFragments() {
List<Fragment> list = new ArrayList<>();
list.add(new FirstFragment());
list.add(new MiddleFragment());
list.add(new LastFragment());
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
viewPager.setAdapter(new TabFragmentPagerAdapter(getSupportFragmentManager(), list));
List<String> listTitle = new ArrayList<>();
listTitle.add("系统组件");
listTitle.add("自定义View");
listTitle.add("第三方库控件");
mTabFragmentPagerAdapter = new TabFragmentPagerAdapter(getSupportFragmentManager(), list, listTitle);
viewPager.setAdapter(mTabFragmentPagerAdapter);
tabLayout.setupWithViewPager(viewPager);
}
use of android.support.v4.view.ViewPager in project Android-skin-support by ximsfei.
the class MaterialDesignActivity method configFragments.
private void configFragments() {
List<Fragment> list = new ArrayList<>();
list.add(new MDFirstFragment());
// list.add(new MiddleFragment());
// list.add(new LastFragment());
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
List<String> listTitle = new ArrayList<>();
listTitle.add("系统组件");
// listTitle.add("自定义View");
// listTitle.add("第三方库控件");
mTabFragmentPagerAdapter = new TabFragmentPagerAdapter(getSupportFragmentManager(), list, listTitle);
viewPager.setAdapter(mTabFragmentPagerAdapter);
tabLayout.setupWithViewPager(viewPager);
}
Aggregations