-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathUseInFragmentActivity.java
104 lines (88 loc) · 3.58 KB
/
UseInFragmentActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.jaeger.statusbarutil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;
import com.jaeger.library.StatusBarUtil;
import com.jaeger.statusbardemo.R;
import java.util.ArrayList;
import java.util.Random;
/**
* Created by Jaeger on 16/8/11.
*
* Email: [email protected]
* GitHub: https://github.com/laobie
*/
public class UseInFragmentActivity extends BaseActivity {
private ViewPager mVpHome;
private BottomNavigationBar mBottomNavigationBar;
private ArrayList<Fragment> mFragmentList = new ArrayList<>();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_use_in_fragment);
mVpHome = (ViewPager) findViewById(R.id.vp_home);
mBottomNavigationBar = (BottomNavigationBar) findViewById(R.id.bottom_navigation_bar);
mBottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.ic_favorite, "One"))
.addItem(new BottomNavigationItem(R.drawable.ic_gavel, "Two"))
.addItem(new BottomNavigationItem(R.drawable.ic_grade, "Three"))
.addItem(new BottomNavigationItem(R.drawable.ic_group_work, "Four"))
.initialise();
mBottomNavigationBar.setTabSelectedListener(new BottomNavigationBar.OnTabSelectedListener() {
@Override
public void onTabSelected(int position) {
mVpHome.setCurrentItem(position);
}
@Override
public void onTabUnselected(int position) {
}
@Override
public void onTabReselected(int position) {
}
});
mFragmentList.add(new ImageFragment());
mFragmentList.add(new SimpleFragment());
mFragmentList.add(new SimpleFragment());
mFragmentList.add(new SimpleFragment());
mVpHome.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
mBottomNavigationBar.selectTab(position);
switch (position) {
case 0:
break;
default:
Random random = new Random();
int color = 0xff000000 | random.nextInt(0xffffff);
if (mFragmentList.get(position) instanceof SimpleFragment) {
((SimpleFragment) mFragmentList.get(position)).setTvTitleBackgroundColor(color);
}
break;
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
mVpHome.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
});
}
@Override
protected void setStatusBar() {
StatusBarUtil.setTranslucentForImageViewInFragment(UseInFragmentActivity.this, null);
}
}