I want to add action on clicking the Menu button on Android device. Suppose user is seeing Graph (one activity) now and he wants to switch to Charts. When user clicks the Menu button it has to show submenu say "Chart" this will be another activity. and then the user will switch to Charts.
How i can accomplish with this? can anybody guide me?
override onMenuItemClicked function and call startActivity()
to add Menu item to an activity you need to override
onCreateMenuItem function.
Related
I'm having a toolbar in which I have a menu option so when the guide button from the menu is clicked the guide activity opens but now I want to add a back arrow on toolbar so I can navigate through button clcik and as I see some solutions many of them are suggesting
android:parentActivityName=".UI.HomeActivity" // UI.HomeActivity is where i want to go back
but I don't know why it doesn't seems to work I was not able to see any arrow on the left of the toolbar
and dont know(correct me if wrong) but tbh using android:parentActivityName=".UI.HomeActivity"
for navigating doesn't looks good to me , i was preferring manaul onClick listner on the icon(as image) in the tool bar , but dont know how do i do that
I'm doing an appication under phonegap (more specific in android). How can I disable the home, menu and back buttons in the screen, the idea is when i press any of the buttons, show a verification dialog, if the answer is correct, close the app. When i assign the function button doesn't show the dialog
For the home menu remove the onCreateOptionsMenu() function and also you wouldn't need the onOptionsItemSelected() function, so to hide the menu remove these two.
For the back buttons there are two of them:
The hard button in device that navigates in the app until it hits the main activity then pops out of the app, can be controlled by overriding this method onBackPressed()
And the one in the action bar that navigates all inside the app itself but never pops the user out of the app, can be set by setDisplayHomeAsUpEnabled() which takes a Boolean true to make it working, false to disable it.
In my app i have to develop a menu using grid view with the icons and a shortcut button for easy switching of language options. So when the user clicks this button, 'English Menu' should switch to 'Urdu Menu' and vice-versa. So do i have to make two menu activities : one in English and on in Urdu and keep switching between them using intent or i should use toggle button instead ? Please suggest. Thanks!
I added all the menu items (in your case, both English AND Urdu menu items) into my menu xml file. And I grouped them as you see here (Menu Resource). And per button click, I set their visibility to either true or false.
(Edit) This is a function in Android Menu class:
setGroupVisible(int group, boolean visible)
Show or hide all menu items that are in the given group.
I get an error with the ActionBar back button when I'm moving back to a previous activity, but when I use the Menu Button Back, everything works as planned! I think I have an idea of what is going on, because using the Action Bar back button causes a recreation of the previous activity, but I don't want that to happen. How do I override the Action Bar (default) back button to perform like the Menu Bar back button so that OnDestroy() is not called?
I figured it out, I had to call finish() in my onMenuItemClicked function rather than using the default function.
This answer may be outdated though.
I have a problem, I need to create menu items but I want the user to be able to do that through a GUI where he/she enters the name of the menu item in an edit text and clicks a button to create it. How do I go about this. I will appreciate the help!
Whether you want to handle menu on user view ie menu as a button not menu key on emulator or device then you can treat menu as general view. you have to handle onclicklistener. in onclick() method create the view that you wan to display to the user.
Donot forget to vote the response if it is helpful for you.
Thanks
Deepak