Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.52 KB | None | 0 0
  1. <Button
  2. android:layout_width="match_parent"
  3. android:layout_height="125dp"
  4. android:text="Today&apos;s Special"
  5. android:id="@+id/button"
  6. android:layout_alignParentTop="true"
  7. android:layout_alignParentLeft="true"
  8. android:layout_alignParentStart="true"
  9. android:layout_alignParentRight="true"
  10. android:layout_alignParentEnd="false" />
  11.  
  12. <Button
  13. android:layout_width="wrap_content"
  14. android:layout_height="125dp"
  15. android:text="Appetizers"
  16. android:id="@+id/button2"
  17. android:layout_below="@+id/button"
  18. android:layout_alignParentLeft="true"
  19. android:layout_alignParentStart="true"
  20. android:layout_alignParentRight="true"
  21. android:layout_alignParentEnd="true"
  22. android:onClick="Go to the Dessert Page"/>
  23.  
  24. <Button
  25. android:layout_width="wrap_content"
  26. android:layout_height="125dp"
  27. android:text="Salads"
  28. android:id="@+id/button3"
  29. android:layout_below="@+id/button2"
  30. android:layout_alignParentLeft="true"
  31. android:layout_alignParentStart="true"
  32. android:layout_alignParentRight="true"
  33. android:layout_alignParentEnd="true" />
  34.  
  35. <Button
  36. android:layout_width="wrap_content"
  37. android:layout_height="125dp"
  38. android:text="Dessert"
  39. android:id="@+id/button4"
  40. android:layout_below="@+id/button3"
  41. android:layout_alignParentLeft="true"
  42. android:layout_alignParentStart="true"
  43. android:layout_alignParentRight="true"
  44. android:layout_alignParentEnd="true" />
  45.  
  46. public class SecondFragment extends Fragment
  47. {
  48. View myView;
  49. @Nullable
  50. @Override
  51. public View onCreateView
  52. (LayoutInflater inflater, ViewGroup container,
  53. Bundle savedInstanceState)
  54. {
  55. myView = inflater.inflate(R.layout.second_layout, container, false);
  56. return myView;
  57. }
  58. }
  59.  
  60. public class MainActivity extends
  61. AppCompatActivity implements
  62. NavigationView.OnNavigationItemSelectedListener
  63. {
  64. @Override
  65. protected void onCreate(Bundle savedInstanceState)
  66. {
  67. super.onCreate(savedInstanceState);
  68. setContentView(R.layout.activity_main);
  69.  
  70. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  71. setSupportActionBar(toolbar);
  72.  
  73. FloatingActionButton fab =
  74. (FloatingActionButton) findViewById(R.id.fab);
  75. fab.setOnClickListener(new View.OnClickListener() {
  76. @Override
  77. public void onClick(View view) {
  78. Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
  79. .setAction("Action", null).show();
  80. }
  81. });
  82.  
  83. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  84. ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  85. drawer.setDrawerListener(toggle);
  86. toggle.syncState();
  87.  
  88. NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
  89. navigationView.setNavigationItemSelectedListener(this);
  90. }
  91.  
  92. @Override
  93. public void onBackPressed() {
  94. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  95. if (drawer.isDrawerOpen(GravityCompat.START)) {
  96. drawer.closeDrawer(GravityCompat.START);
  97. } else {
  98. super.onBackPressed();
  99. }
  100. }
  101.  
  102. @Override
  103. public boolean onCreateOptionsMenu(Menu menu) {
  104. // Inflate the menu; this adds items to the action bar if it is present.
  105. getMenuInflater().inflate(R.menu.main, menu);
  106. return true;
  107. }
  108.  
  109. @Override
  110. public boolean onOptionsItemSelected(MenuItem item) {
  111. // Handle action bar item clicks here. The action bar will
  112. // automatically handle clicks on the Home/Up button, so long
  113. // as you specify a parent activity in AndroidManifest.xml.
  114. int id = item.getItemId();
  115.  
  116. //noinspection SimplifiableIfStatement
  117. if (id == R.id.action_settings) {
  118. return true;
  119. }
  120.  
  121. return super.onOptionsItemSelected(item);
  122. }
  123.  
  124. @SuppressWarnings("StatementWithEmptyBody")
  125. @Override
  126. public boolean onNavigationItemSelected(MenuItem item) {
  127. // Handle navigation view item clicks here.
  128. int id = item.getItemId();
  129. FragmentManager fragmentManager = getFragmentManager();
  130.  
  131. if (id == R.id.nav_first_layout)
  132. {
  133. fragmentManager.beginTransaction()
  134. .replace(R.id.content_frame
  135. , new FirstFragment())
  136. .commit();
  137. // Handle the camera action
  138. }
  139. else if (id == R.id.nav_second_layout)
  140. {
  141. fragmentManager.beginTransaction()
  142. .replace(R.id.content_frame
  143. , new SecondFragment())
  144. .commit();
  145.  
  146. }
  147. else if (id == R.id.nav_third_layout)
  148. {
  149. fragmentManager.beginTransaction()
  150. .replace(R.id.content_frame
  151. , new ThirdFragment())
  152. .commit();
  153.  
  154. }
  155. else if (id == R.id.nav_fourth_layout)
  156. {
  157. fragmentManager.beginTransaction()
  158. .replace(R.id.content_frame
  159. , new FourthFragment())
  160. .commit();
  161. }
  162. else if (id == R.id.nav_fifth_layout)
  163. {
  164. fragmentManager.beginTransaction()
  165. .replace(R.id.content_frame
  166. , new FifthFragment())
  167. .commit();
  168. }
  169.  
  170. else if (id == R.id.button)
  171. {
  172. fragmentManager.beginTransaction()
  173. .replace(R.id.content_frame
  174. , new FifthFragment())
  175. .commit();
  176. }
  177.  
  178. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  179. drawer.closeDrawer(GravityCompat.START);
  180. return true;
  181. }
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement