Guest User

Untitled

a guest
Aug 20th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.81 KB | None | 0 0
  1. public class Home extends AppCompatActivity
  2. implements NavigationView.OnNavigationItemSelectedListener {
  3.  
  4. TextView txtFullName;
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.activity_home); //(Home.java:27)
  9.  
  10. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  11. toolbar.setTitle("Menu Management");
  12. setSupportActionBar(toolbar);
  13.  
  14. FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
  15. fab.setOnClickListener(new View.OnClickListener() {
  16. @Override
  17. public void onClick(View view) {
  18. Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
  19. .setAction("Action", null).show();
  20. }
  21. });
  22.  
  23. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  24. ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
  25. this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  26. drawer.addDrawerListener(toggle);
  27. toggle.syncState();
  28.  
  29. NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
  30. navigationView.setNavigationItemSelectedListener(this);
  31.  
  32. //Set name for user
  33. View headerView = navigationView.getHeaderView(0);
  34. txtFullName = (TextView)headerView.findViewById(R.id.txtFullName);
  35. txtFullName.setText(Common.currentUser.getName());
  36. }
  37.  
  38. @Override
  39. public void onBackPressed() {
  40. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  41. if (drawer.isDrawerOpen(GravityCompat.START)) {
  42. drawer.closeDrawer(GravityCompat.START);
  43. } else {
  44. super.onBackPressed();
  45. }
  46. }
  47.  
  48. @Override
  49. public boolean onCreateOptionsMenu(Menu menu) {
  50. // Inflate the menu; this adds items to the action bar if it is present.
  51. getMenuInflater().inflate(R.menu.home, menu);
  52. return true;
  53. }
  54.  
  55. @Override
  56. public boolean onOptionsItemSelected(MenuItem item) {
  57. // Handle action bar item clicks here. The action bar will
  58. // automatically handle clicks on the Home/Up button, so long
  59. // as you specify a parent activity in AndroidManifest.xml.
  60. int id = item.getItemId();
  61.  
  62. //noinspection SimplifiableIfStatement
  63. if (id == R.id.action_settings) {
  64. return true;
  65. }
  66.  
  67. return super.onOptionsItemSelected(item);
  68. }
  69.  
  70. @SuppressWarnings("StatementWithEmptyBody")
  71. @Override
  72. public boolean onNavigationItemSelected(MenuItem item) {
  73. // Handle navigation view item clicks here.
  74. int id = item.getItemId();
  75.  
  76.  
  77.  
  78. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  79. drawer.closeDrawer(GravityCompat.START);
  80. return true;
  81. }
  82.  
  83. <resources>
  84.  
  85. <!-- Base application theme. -->
  86. <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
  87. <!-- Customize your theme here. -->
  88. <item name="colorPrimary">@color/colorPrimary</item>
  89. <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
  90. <item name="colorAccent">@color/colorAccent</item>
  91. <item name="windowActionBar">false</item>
  92. <item name="windowNoTitle">true</item>
  93. </style>
  94.  
  95.  
  96. <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
  97.  
  98. <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
  99.  
  100. <style name="CollapsedAppbar" parent="@android:style/TextAppearance.Medium">
  101. <item name="android:textSize">24sp</item>
  102. <item name="android:textColor">@android:color/white</item>
  103. <item name="android:textStyle">normal</item>
  104. </style>
  105.  
  106. <resources>
  107.  
  108. <style name="AppTheme.NoActionBar">
  109. <item name="windowActionBar">false</item>
  110. <item name="windowNoTitle">true</item>
  111. <item name="android:statusBarColor">@android:color/transparent</item>
  112. </style>
  113.  
  114.  
  115.  
  116. <style name="ExpendedAppbar" parent="@android:style/TextAppearance.Material.Title">
  117. <item name="android:textColor">@color/colorPrimary</item>
  118. <item name="android:textStyle">normal</item>
  119. </style>
  120.  
  121. <?xml version="1.0" encoding="utf-8"?>
  122.  
  123. <application
  124. android:allowBackup="true"
  125. android:icon="@mipmap/ic_launcher"
  126. android:label="@string/app_name"
  127. android:roundIcon="@mipmap/ic_launcher_round"
  128. android:supportsRtl="true"
  129. android:theme="@style/AppTheme">
  130. <activity android:name=".MainActivity">
  131. <intent-filter>
  132. <action android:name="android.intent.action.MAIN" />
  133.  
  134. <category android:name="android.intent.category.LAUNCHER" />
  135. </intent-filter>
  136. </activity>
  137. <activity
  138. android:name=".Home"
  139. android:label="@string/title_activity_home"
  140. android:theme="@style/AppTheme.NoActionBar" />
  141. <activity android:name=".SignIn"></activity>
  142. </application>
  143.  
  144. E/AndroidRuntime: FATAL EXCEPTION: main
  145. java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mohamed.myapplicationserveur/com.example.mohamed.myapplicationserveur.Home}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
  146. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
  147. at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
  148. at android.app.ActivityThread.access$600(ActivityThread.java:141)
  149. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
  150. at android.os.Handler.dispatchMessage(Handler.java:99)
  151. at android.os.Looper.loop(Looper.java:137)
  152. at android.app.ActivityThread.main(ActivityThread.java:5103)
  153. at java.lang.reflect.Method.invokeNative(Native Method)
  154. at java.lang.reflect.Method.invoke(Method.java:525)
  155. at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
  156. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  157. at dalvik.system.NativeStart.main(Native Method)
  158. Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
  159. at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:354)
  160. at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323)
  161. at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
  162. at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
  163. at com.example.mohamed.myapplicationserveur.Home.onCreate(Home.java:27)
  164. at android.app.Activity.performCreate(Activity.java:5133)
  165. at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  166. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
Add Comment
Please, Sign In to add comment