Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.08 KB | None | 0 0
  1. Caused by: android.view.InflateException: Binary XML file line #28: Error inflating class android.support.design.widget.NavigationView
  2.  
  3. <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4. xmlns:app="http://schemas.android.com/apk/res-auto"
  5. xmlns:tools="http://schemas.android.com/tools"
  6. android:id="@+id/drawer"
  7. android:layout_width="match_parent"
  8. android:layout_height="match_parent"
  9. android:fitsSystemWindows="true"
  10. tools:context=".MainActivity">
  11.  
  12. <LinearLayout
  13. android:layout_width="match_parent"
  14. android:layout_height="match_parent"
  15. android:orientation="vertical">
  16.  
  17. <include
  18. android:id="@+id/tool_bar"
  19. layout="@layout/tool_bar" />
  20.  
  21. <FrameLayout
  22. android:id="@+id/frame"
  23. android:layout_width="match_parent"
  24. android:layout_height="match_parent">
  25.  
  26. </FrameLayout>
  27.  
  28. </LinearLayout>
  29.  
  30. <android.support.design.widget.NavigationView
  31. android:id="@+id/navigation_view"
  32. android:layout_width="wrap_content"
  33. android:layout_height="match_parent"
  34. android:layout_gravity="start"
  35. app:headerLayout="@layout/header"
  36. app:menu="@menu/drawer" />
  37. </android.support.v4.widget.DrawerLayout>
  38.  
  39. import android.support.design.widget.NavigationView;
  40. import android.support.v4.widget.DrawerLayout;
  41. import android.support.v7.app.ActionBarDrawerToggle;
  42. import android.support.v7.app.AppCompatActivity;
  43. import android.os.Bundle;
  44. import android.support.v7.widget.Toolbar;
  45. import android.view.Menu;
  46. import android.view.MenuItem;
  47. import android.view.View;
  48. import android.widget.Toast;
  49.  
  50. public class MainActivity extends AppCompatActivity {
  51.  
  52. //Defining Variables
  53. private Toolbar toolbar;
  54. private NavigationView navigationView;
  55. private DrawerLayout drawerLayout;
  56.  
  57. @Override
  58. protected void onCreate(Bundle savedInstanceState) {
  59. super.onCreate(savedInstanceState);
  60. setContentView(R.layout.activity_main);
  61.  
  62. // Initializing Toolbar and setting it as the actionbar
  63. toolbar = (Toolbar) findViewById(R.id.tool_bar);
  64. setSupportActionBar(toolbar);
  65.  
  66. //Initializing NavigationView
  67. navigationView = (NavigationView) findViewById(R.id.navigation_view);
  68.  
  69. //Setting Navigation View Item Selected Listener to handle the item click of the navigation menu
  70. navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
  71.  
  72. // This method will trigger on item Click of navigation menu
  73. @Override
  74. public boolean onNavigationItemSelected(MenuItem menuItem) {
  75.  
  76. //Checking if the item is in checked state or not, if not make it in checked state
  77. if (menuItem.isChecked()) menuItem.setChecked(false);
  78. else menuItem.setChecked(true);
  79.  
  80. //Closing drawer on item click
  81. drawerLayout.closeDrawers();
  82.  
  83. //Check to see which item was being clicked and perform appropriate action
  84. switch (menuItem.getItemId()) {
  85.  
  86. //Replacing the main content with ContentFragment Which is our Inbox View;
  87. case R.id.inbox:
  88. Toast.makeText(getApplicationContext(), "Inbox Selected", Toast.LENGTH_SHORT).show();
  89. ContentFragment fragment = new ContentFragment();
  90. android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
  91. fragmentTransaction.replace(R.id.frame, fragment);
  92. fragmentTransaction.commit();
  93. return true;
  94.  
  95. // For rest of the options we just show a toast on click
  96. case R.id.starred:
  97. Toast.makeText(getApplicationContext(), "Stared Selected", Toast.LENGTH_SHORT).show();
  98. return true;
  99. case R.id.sent_mail:
  100. Toast.makeText(getApplicationContext(), "Send Selected", Toast.LENGTH_SHORT).show();
  101. return true;
  102. case R.id.drafts:
  103. Toast.makeText(getApplicationContext(), "Drafts Selected", Toast.LENGTH_SHORT).show();
  104. return true;
  105. case R.id.allmail:
  106. Toast.makeText(getApplicationContext(), "All Mail Selected", Toast.LENGTH_SHORT).show();
  107. return true;
  108. case R.id.trash:
  109. Toast.makeText(getApplicationContext(), "Trash Selected", Toast.LENGTH_SHORT).show();
  110. return true;
  111. case R.id.spam:
  112. Toast.makeText(getApplicationContext(), "Spam Selected", Toast.LENGTH_SHORT).show();
  113. return true;
  114. default:
  115. Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show();
  116. return true;
  117. }
  118. }
  119. });
  120.  
  121. // Initializing Drawer Layout and ActionBarToggle
  122. drawerLayout = (DrawerLayout) findViewById(R.id.drawer);
  123. ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.openDrawer, R.string.closeDrawer) {
  124.  
  125. @Override
  126. public void onDrawerClosed(View drawerView) {
  127. // Code here will be triggered once the drawer closes as we dont want anything to happen so we leave this blank
  128. super.onDrawerClosed(drawerView);
  129. }
  130.  
  131. @Override
  132. public void onDrawerOpened(View drawerView) {
  133. // Code here will be triggered once the drawer open as we dont want anything to happen so we leave this blank
  134. super.onDrawerOpened(drawerView);
  135. }
  136. };
  137.  
  138. //Setting the actionbarToggle to drawer layout
  139. drawerLayout.setDrawerListener(actionBarDrawerToggle);
  140.  
  141. //calling sync state is necessay or else your hamburger icon wont show up
  142. actionBarDrawerToggle.syncState();
  143. }
  144.  
  145. @Override
  146. public boolean onCreateOptionsMenu(Menu menu) {
  147. // Inflate the menu; this adds items to the action bar if it is present.
  148. getMenuInflater().inflate(R.menu.menu_main, menu);
  149. return true;
  150. }
  151.  
  152. @Override
  153. public boolean onOptionsItemSelected(MenuItem item) {
  154. // Handle action bar item clicks here. The action bar will
  155. // automatically handle clicks on the Home/Up button, so long
  156. // as you specify a parent activity in AndroidManifest.xml.
  157. int id = item.getItemId();
  158.  
  159. //noinspection SimplifiableIfStatement
  160. if (id == R.id.action_settings) {
  161. return true;
  162. }
  163. return super.onOptionsItemSelected(item);
  164. }
  165. }
  166.  
  167. apply plugin: 'com.android.application'
  168.  
  169. android {
  170. compileSdkVersion 23
  171. buildToolsVersion '23.0.0'
  172.  
  173. defaultConfig {
  174. applicationId "com.example.mobinamanzai.projectalpha"
  175. minSdkVersion 17
  176. targetSdkVersion 23
  177. versionCode 1
  178. versionName "1.0"
  179. }
  180. buildTypes {
  181. release {
  182. minifyEnabled false
  183. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  184. }
  185. debug {
  186. debuggable true
  187. }
  188. }
  189. }
  190.  
  191. dependencies {
  192. compile fileTree(dir: 'libs', include: ['*.jar'])
  193.  
  194. compile 'com.android.support:support-v4:23.0.0'
  195. compile 'com.android.support:appcompat-v7:23.0.0'
  196. compile 'com.android.support:design:23.0.0'
  197. compile 'de.hdodenhof:circleimageview:1.3.0'
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement