Решил опробовать данное решение.
https://github.com/mxn21/FlowingDrawer. Проблема никак не могу обработать события с кнопок.
Главное фрагмент fragment_menu.xml
XML |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.NavigationView
android:id="@+id/vNavigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/transparent"
app:headerLayout="@layout/view_global_menu_header"
app:itemIconTint="#8b8b8b"
app:itemTextColor="#666666"
app:menu="@menu/drawer_menu"/>
</RelativeLay |
|
drawer_menu.xml
XML |
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
| <menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:id="@+id/menu_group_1">
<item
android:id="@+id/menu_feed"
android:icon="@drawable/ic_global_menu_feed"
android:title="My Feed" />
<item
android:id="@+id/menu_direct"
android:icon="@drawable/ic_global_menu_direct"
android:title="Instagram Direct" />
<item
android:id="@+id/menu_news"
android:icon="@drawable/ic_global_menu_news"
android:title="News" />
<item
android:id="@+id/menu_popular"
android:icon="@drawable/ic_global_menu_popular"
android:title="Popular" />
<item
android:id="@+id/menu_photos_nearby"
android:icon="@drawable/ic_global_menu_nearby"
android:title="Photos Nearby" />
<item
android:id="@+id/menu_photo_you_liked"
android:icon="@drawable/ic_global_menu_likes"
android:title="Photos You've Liked" />
</group>
<group android:id="@+id/menu_group_2">
<item
android:id="@+id/menu_settings"
android:title="Settings" />
<item
android:id="@+id/menu_about"
android:title="About" />
</group>
</menu> |
|
MainActivity
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
| public class MainActivity extends AppCompatActivity {
private RecyclerView rvFeed;
private LeftDrawerLayout mLeftDrawerLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupToolbar();
mLeftDrawerLayout = (LeftDrawerLayout) findViewById(R.id.id_drawerlayout);
rvFeed = (RecyclerView) findViewById(R.id.rvFeed);
FragmentManager fm = getSupportFragmentManager();
MyMenuFragment mMenuFragment = (MyMenuFragment) fm.findFragmentById(R.id.id_container_menu);
FlowingView mFlowingView = (FlowingView) findViewById(R.id.sv);
if (mMenuFragment == null) {
fm.beginTransaction().add(R.id.id_container_menu, mMenuFragment = new MyMenuFragment()).commit();
}
mLeftDrawerLayout.setFluidView(mFlowingView);
mLeftDrawerLayout.setMenuFragment(mMenuFragment);
setupFeed();
// NavigationView navigationView = (NavigationView) findViewById(R.id.vNavigation);
//navigationView.setNavigationItemSelectedListener(this);
}
protected void setupToolbar() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setNavigationIcon(R.drawable.ic_menu_white);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mLeftDrawerLayout.toggle();
}
});
}
}
private void setupFeed() {
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this) {
@Override
protected int getExtraLayoutSpace(RecyclerView.State state) {
return 300;
}
};
rvFeed.setLayoutManager(linearLayoutManager);
FeedAdapter feedAdapter = new FeedAdapter(this);
rvFeed.setAdapter(feedAdapter);
feedAdapter.updateItems();
}
@Override
public void onBackPressed() {
if (mLeftDrawerLayout.isShownMenu()) {
mLeftDrawerLayout.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
} |
|
Пытался обработать:
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
| public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.drawer_menu, menu);
return true;
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.menu_news) {
Toast toast = Toast.makeText(getApplicationContext(),
"Ура", Toast.LENGTH_SHORT);
toast.show();
} if (id == R.id.menu_popular) {
Toast toast = Toast.makeText(getApplicationContext(),
"Ура", Toast.LENGTH_SHORT);
toast.show();
} if (id == R.id.menu_about) {
Toast toast = Toast.makeText(getApplicationContext(),
"Ура", Toast.LENGTH_SHORT);
toast.show();
}
return super.onOptionsItemSelected(item);
}
} |
|