Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2. protected BottomNavigationView bottomNavigationView;
  3. protected FrameLayout frameLayout;
  4.  
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.activity_main);
  9.  
  10. frameLayout = (FrameLayout) findViewById(R.id.content_frame);
  11. bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
  12. bottomNavigationView.setOnNavigationItemSelectedListener(
  13. new BottomNavigationView.OnNavigationItemSelectedListener() {
  14. @Override
  15. public boolean onNavigationItemSelected(@NonNull MenuItem item) {
  16. switch (item.getItemId()) {
  17. case R.id.action_subscribed:
  18. startActivity(new Intent(getApplicationContext(), SubscribedShowsActivity.class));
  19. break;
  20. case R.id.action_search:
  21. startActivity(new Intent(getApplicationContext(), SearchActivity.class));
  22. break;
  23. case R.id.action_upcoming:
  24. startActivity(new Intent(getApplicationContext(), UpcomingEpisodesActivity.class));;
  25. break;
  26. }
  27. return true;
  28. }
  29. });
  30. }
  31.  
  32. <?xml version="1.0" encoding="utf-8"?>
  33. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  34. xmlns:app="http://schemas.android.com/apk/res-auto"
  35. android:layout_width="match_parent"
  36. android:layout_height="match_parent">
  37.  
  38. <FrameLayout
  39. android:layout_height="match_parent"
  40. android:layout_width="match_parent"
  41. android:id="@+id/content_frame"/>
  42.  
  43. <android.support.design.widget.BottomNavigationView
  44. android:id="@+id/bottom_navigation"
  45. android:layout_width="match_parent"
  46. android:layout_height="wrap_content"
  47. android:layout_alignParentBottom="true"
  48. app:itemBackground="@color/colorPrimary"
  49. app:itemIconTint="@drawable/nav_item_color_state"
  50. app:itemTextColor="@drawable/nav_item_color_state"
  51. app:menu="@menu/bottom_navigation_main" />
  52.  
  53. </RelativeLayout>
  54.  
  55. public class SubscribedShowsActivity extends MainActivity {
  56.  
  57. @Override
  58. protected void onCreate(Bundle savedInstanceState) {
  59. super.onCreate(savedInstanceState);
  60.  
  61. LayoutInflater inflater = (LayoutInflater) this
  62. .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  63. View contentView = inflater.inflate(R.layout.activity_upcoming_episodes, null, false);
  64. bottomNavigationView.addView(contentView, 0);
  65.  
  66. if (savedInstanceState == null) {
  67. getSupportFragmentManager().beginTransaction()
  68. .add(R.id.content_frame, new SubscribedShowsFragment())
  69. .commit();
  70. }
  71. }
  72. }
  73.  
  74. @Override
  75. protected void onCreate(Bundle savedInstanceState) {
  76. super.onCreate(savedInstanceState);
  77.  
  78. LayoutInflater inflater = (LayoutInflater) this
  79. .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  80. View contentView = inflater.inflate(R.layout.activity_search, null, false);
  81. bottomNavigationView.addView(contentView, 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement