Android options menu tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 พ.ย. 2024

ความคิดเห็น • 82

  • @99Points
    @99Points 4 ปีที่แล้ว

    *Is it possible to show both the name as well as a icon of a item in the option menu?*
    An excellent video by the way. I really learned a lot. Thank You!

    • @CodingDemos
      @CodingDemos  4 ปีที่แล้ว

      Hi, yeah it's possible. I wrote a tutorial that shows you how to do it. Here is the link: www.codingdemos.com/android-options-menu-icon/

  • @ultimat.
    @ultimat. 4 ปีที่แล้ว

    Bravo bravo j'attends d'autres tutoriels utiles pour des fonctions ou des développements d'applications

  • @silentmwatsika3964
    @silentmwatsika3964 7 ปีที่แล้ว +4

    which android studio version was used in this tutorial?

  • @zonico5826
    @zonico5826 7 ปีที่แล้ว

    The android documentation is recommending the use of xml files, etc and not toolbar, is the a special case, where its more appropriate to use the toolbar?

    • @CodingDemos
      @CodingDemos  7 ปีที่แล้ว +1

      Yes and i'm creating the menu items inside my_menu.xml file as shown in the video, once you set those menu item they will show up in the toolbar.
      You can also put a spinner (Dropdown menu) inside the toolbar as i did in this video: th-cam.com/video/CvO0Ng-_C6A/w-d-xo.html

  • @jerzonemingui2943
    @jerzonemingui2943 5 ปีที่แล้ว

    Great tutorial!You just earn a subscriber!
    How to change the text size of the menu items?

  • @dwestley74
    @dwestley74 6 ปีที่แล้ว

    Thanks for the great tutorial! Learned all I needed to know about menus.

  • @99Points
    @99Points 4 ปีที่แล้ว

    I have one question.
    why should someone create a *toolbar* when we can display option menu in the action bar?

    • @CodingDemos
      @CodingDemos  4 ปีที่แล้ว

      Hi, creating a toolbar will give you the ability to customize it by adding more functions and animations

    • @99Points
      @99Points 4 ปีที่แล้ว

      @@CodingDemos If we want no app title on the toolbar we just need this code, right?
      Toolbar mtoolbaar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(mtoolbaar);
      *getSupportActionBar().setDisplayShowTitleEnabled(false);*

  • @TropicalCoder
    @TropicalCoder 5 ปีที่แล้ว

    Very well presented

  • @MrGPgue0857
    @MrGPgue0857 7 ปีที่แล้ว

    it's awesome! may i ask u a question? how to hide the app_name "OptionsMenuTutorial"? thanks a lot!

  • @mohamadalomair2028
    @mohamadalomair2028 7 ปีที่แล้ว +1

    Many Thanks, I have added new Menu Items to my App.

  • @tjkoid9085
    @tjkoid9085 7 ปีที่แล้ว +1

    Glad to come to your tutorial, good explanation. THUMBS UP!

    • @CodingDemos
      @CodingDemos  7 ปีที่แล้ว

      Thanks for watching :)

  • @thoriqanwar5882
    @thoriqanwar5882 7 ปีที่แล้ว +1

    Hey, do you know why my sidebar navigation is always close when i click to 1 of the menu ??

    • @CodingDemos
      @CodingDemos  7 ปีที่แล้ว

      That is the correct behavior, when you open the sidebar navigation and select a menu item it will close sidebar navigation in order to show the right page in full screen. For example you can open the Play Store application and you will notice the same thing

  • @oreloffir3551
    @oreloffir3551 7 ปีที่แล้ว +1

    Tnx , thisis very good guid.
    but i have a little problem :
    when i try to do the if statment i cant find the item that i creat in my_menu.xml
    Code:
    MainActivity|
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.menu_login){
    }
    main_menu.xml|

    • @CodingDemos
      @CodingDemos  7 ปีที่แล้ว

      Hi, based on the code given i don't see the part where you have override the onCreateOptionsMenu..You need to override that method so you can inflate the menu layout which is main_menu.xml..like this:
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater mMenuInflater = getMenuInflater();
      mMenuInflater.inflate(R.menu.my_menu, menu);
      return true;
      }
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
      if (item.getItemId() == R.id.menu_login) {
      Toast.makeText(MainActivity.this,
      "You have clicked on login menu",
      Toast.LENGTH_SHORT)
      .show();
      }
      return super.onOptionsItemSelected(item);
      }
      Note: Please remove "android2:title="Login" from menu item
      Please do let me know if need help with the code.
      Happy coding :)

  • @sefaaydin2029
    @sefaaydin2029 6 ปีที่แล้ว

    thank you so much.
    I do not know the exact English, but I can understand what you did with your codes.
    Briefly as the subtitle dials: D

  • @job2k6
    @job2k6 6 ปีที่แล้ว

    Great tutorial. Appreciate it.

  • @mamonurrashidshohel8796
    @mamonurrashidshohel8796 7 ปีที่แล้ว +1

    Do you have database tutorial and all about continuously ?

  • @yannicksprenger9563
    @yannicksprenger9563 7 ปีที่แล้ว +1

    Sorry to bother but what if I wanted to get a redirect to a webpage instead of just showing a message? what would I have to change?

    • @CodingDemos
      @CodingDemos  7 ปีที่แล้ว

      Hi, i'm sorry for the late reply...To open a webpage you will need to use an Intent and here is how to do it:
      - First declare a variable that will hold the webpage URL that you want to open: String website = "www.google.com";
      - Now if you use that URL that doesn't start with http or https then you will not be able to open the webpage, that's why we need to handle it like this:
      if (!website.startsWith("") && !website.startsWith("")) {
      website = "" + website;
      }
      - Next we add an Intent that will open the webpage like this:
      Intent mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(website));
      - Finally we need to check whether the user's device have an app installed that will handle this type of action like this, otherwise show a toast message to the user with an explanation:
      if (mIntent.resolveActivity(getPackageManager()) != null) {
      startActivity(mIntent);
      }else{
      Toast.makeText(MainActivity.this,"There is no app that will handle this action",
      Toast.LENGTH_SHORT).show();
      }
      Note: It's recommended to perform the last step because sometimes the user's device may not have an app that could handle that action, which will later lead to app crash!
      The final code looks like this:
      if (item.getItemId() == R.id.action_setting) {
      String website = "www.google.com";
      if (!website.startsWith("") && !website.startsWith("")) {
      website = "" + website;
      }
      Intent mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(website));
      if (mIntent.resolveActivity(getPackageManager()) != null) {
      startActivity(mIntent);
      }
      }
      I hope that helps and happy coding :)

  • @mehakmumtaz31
    @mehakmumtaz31 3 ปีที่แล้ว

    I have an error in setsupportAction(m toolbar)

  • @naimat6143
    @naimat6143 8 ปีที่แล้ว

    Thank you man, keep going good work

    • @CodingDemos
      @CodingDemos  8 ปีที่แล้ว

      Thanks for watching :)

  • @thoriqanwar5882
    @thoriqanwar5882 7 ปีที่แล้ว +1

    how to create something like that but no use of tool bar? by action bar default?

    • @CodingDemos
      @CodingDemos  7 ปีที่แล้ว

      Just skip the part where i changed the parent theme in styles.xml, the toolbar initialization in xml file, and follow the rest of the tutorial

  • @suma4m
    @suma4m 6 ปีที่แล้ว

    There is "android.support.v7.widget.Toolbar" and android.widget.Toolbar". The latter uses "setActionBar(mToolbar)".

    • @CodingDemos
      @CodingDemos  6 ปีที่แล้ว +1

      Hi, the v7 widget toolbar is used for backwards compatibility with older versions of Android

  • @hafizoktri3847
    @hafizoktri3847 7 ปีที่แล้ว

    say I have a share button on toolbar which subject and extra text are need to fetch from json object. can you tell me how to do it?

    • @CodingDemos
      @CodingDemos  7 ปีที่แล้ว

      It depends on what type of data that you want retrieve from the json object that you want share when the user tap on the share button. Let's say if you have a food app, you can allow the user who taps on share button to share dish name and the instructions on how to cook that dish

  • @287MdSahil
    @287MdSahil 5 ปีที่แล้ว

    This was really helpful.

  • @2k4you1
    @2k4you1 7 ปีที่แล้ว

    Error:(8) No resource identifier found for attribute 'orderInCategory' in package 'android', I keep getting this error :(

  • @keremoflu
    @keremoflu 7 ปีที่แล้ว +1

    well detailed, nice

    • @CodingDemos
      @CodingDemos  7 ปีที่แล้ว

      Thanks for watching :)

  • @retroradar_de
    @retroradar_de 7 ปีที่แล้ว

    Thx was really helpful tutorial

  • @ronnelsecusana4705
    @ronnelsecusana4705 6 ปีที่แล้ว

    how can i resolve this it says error: incompatible types: View cannot be converted to Toolbar

    • @CodingDemos
      @CodingDemos  6 ปีที่แล้ว

      Hi, can you show me code for the Toolbar?

  • @PenF1000
    @PenF1000 7 ปีที่แล้ว +1

    thank man you have been a great help!

  • @gregory7645
    @gregory7645 7 ปีที่แล้ว

    "(R.menu.stats_menu, menu)"
    the first "menu" of this line is underlined, could you help me plz ???

    • @CodingDemos
      @CodingDemos  7 ปีที่แล้ว

      Can you tell me what is the error message that you get?

    • @CodingDemos
      @CodingDemos  7 ปีที่แล้ว

      Please can you share with me part of the code that you currently have the issue! You can find my email in the about section of this channel

  • @michaelndale
    @michaelndale 6 ปีที่แล้ว

    Yeah very very Great tutorail !!
    thanks

  • @user-tu7rh2hr1n
    @user-tu7rh2hr1n 4 ปีที่แล้ว

    thnxx buddy

  • @Vmarguirott
    @Vmarguirott 6 ปีที่แล้ว

    Thank you very much for the video, it was what I really needed (Y)

  • @tonmoykhan7153
    @tonmoykhan7153 7 ปีที่แล้ว

    perfect tutorial

  • @niels.faurskov
    @niels.faurskov 7 ปีที่แล้ว

    Very helpful :D

  • @the.ponderer
    @the.ponderer 7 ปีที่แล้ว +1

    good work bro!

    • @CodingDemos
      @CodingDemos  7 ปีที่แล้ว

      Thanks for watching :)

  • @pratyushsingh3967
    @pratyushsingh3967 7 ปีที่แล้ว

    really helpful

  • @thoriqanwar5882
    @thoriqanwar5882 7 ปีที่แล้ว +1

    how to create change activity when click About US ?

    • @CodingDemos
      @CodingDemos  7 ปีที่แล้ว

      Hi, Inside onOptionsItemSelected method whenever you tap on about us menu option instead of showing a toast message like in the video you change that to something like this:
      if(Item.getItemId() == R.id.action_about_us){
      startActivity(new Intent(MainActivity.this, AboutUsActivity.class));
      }

    • @thoriqanwar5882
      @thoriqanwar5882 7 ปีที่แล้ว

      Thanks Coding Demos!

    • @thoriqanwar5882
      @thoriqanwar5882 7 ปีที่แล้ว

      now it create problem Error:Error: Expected resource of type menu [ResourceType]

    • @thoriqanwar5882
      @thoriqanwar5882 7 ปีที่แล้ว +1

      solved

  • @10fersen
    @10fersen 6 ปีที่แล้ว

    App instantly closes after running and no error message is displayed.

    • @CodingDemos
      @CodingDemos  6 ปีที่แล้ว

      Hi, there is no error message in the logcat? Try to clean and build your project

  • @UchigaItachi16
    @UchigaItachi16 6 ปีที่แล้ว

    Is it possible to delete or change the text where it says "OptionMenuTutorial"?
    and thanks for the video

    • @CodingDemos
      @CodingDemos  6 ปีที่แล้ว

      Hi, yeah you can. Just open up strings.xml file, in the file you will see value for app name where you can change it to anything that you like :)

    • @UchigaItachi16
      @UchigaItachi16 6 ปีที่แล้ว

      It works, but that change the name of the app too, so the text is always that name?

    • @CodingDemos
      @CodingDemos  6 ปีที่แล้ว

      Yeah that text actually represent the name of the app. If you want to change the title of a particular screen/page you will do something like this: after you have initialized the toolbar with it's ID, you do toolbar.setTitle("screen name");

  • @kleberkibe
    @kleberkibe 7 ปีที่แล้ว

    thx friend

  • @anuragpathak3441
    @anuragpathak3441 6 ปีที่แล้ว

    why m not able to click om menu

    • @CodingDemos
      @CodingDemos  6 ปีที่แล้ว

      Hi, do you see any errors?

  • @Bigcocoabear
    @Bigcocoabear 7 ปีที่แล้ว +1

    Thanks for your help, this tutorial is good :)

    • @CodingDemos
      @CodingDemos  7 ปีที่แล้ว +1

      Your welcome, happy coding :)

  • @nshusa99
    @nshusa99 7 ปีที่แล้ว +3

    doesn't work in latest android (edit: fixed)

    • @CodingDemos
      @CodingDemos  7 ปีที่แล้ว +1

      Does the app crash or do you see any errors in the logcat?

    • @nshusa99
      @nshusa99 7 ปีที่แล้ว +2

      Yeah I run the app and it says "Name of App has stopped" and closes the app. The error I get in Logcat is " Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor"

    • @CodingDemos
      @CodingDemos  7 ปีที่แล้ว +2

      Did you change the parent theme inside styles.xml file to this (Theme.AppCompat.Light.NoActionBar)?

    • @nshusa99
      @nshusa99 7 ปีที่แล้ว +2

      Thanks! :D

    • @CodingDemos
      @CodingDemos  7 ปีที่แล้ว +1

      Your welcome :)

  • @kingc2001
    @kingc2001 6 ปีที่แล้ว

    with your tutorial android studio get error : R doesn't exist...

    • @CodingDemos
      @CodingDemos  6 ปีที่แล้ว

      Hi, try to restart Android Studio by clicking on File\Invalidate caches/restart and then click on (Just Restart) button