How to make an overflow menu like in Chrome? - android

I would like to make an overflow menu similar to the chrome app in android in which it has the forward, backward and bookmark buttons inside it.
This is the overflow menu in the chrome app.
Any ideas?

You can't have custom views for your overflow menu items, so Chrome is not using the standard action bar. It's weird that Google doesn't even use its own standard tools that it pushes for everyone else to use, but that's just how it goes.
If you load up an app that uses the real standard ActionBar (for example, Calendar or Messaging), it'll have a view in the hierarchy called an ActionBarContainer and you can follow it down all the way to the overflow button, which is an ActionMenuPresenter$OverflowMenuButton.
But load up Chrome in the Hierarchy Viewer, and you'll find out that what they use for the overflow button is just an ImageButton.
Obviously you can either make your own full-on ActionBar implementation, or add an overflow button to the existing ActionBar and somehow make sure the real overflow button never gets displayed. You might find the ActionBar compatibility sample project useful in making a fake actionbar. Either way, if you again look in the Hierarchy Viewer, they're just using a PopupMenu to display the menus in both the real ActionBar apps and the Chrome app.
Hopefully that helps enough to get you started.

Have a look to Android ActionBar for the whole component.
For the sole layout, you can inflate any layout and place it anywhere you want...

Related

Navigation Drawer Toggle Icon without toolbar

So I'm basically a total beginner in things of app programming.
I started with the "Navigation Drawer Activity" from Android studio and my problem is, I want the nav drawer toggle icon (top left corner) and the "3 dotted icon" (top right corner), but I don't want it in a toolbar.
My question is, should I remove the toolbar and keep the Icons (if so, how could I do that) or should I make the toolbar fullscreen (don't know how to remove the appname)?
Or is there any better way? Like starting from scratch and placing the icons where I want?
Thanks in advance!
What you see as "nav drawer toggle icon" is actually an ActionBarDrawerToggle object and as its name suggests it can only reside in a Toolbar.
The "3 dotted icon" is the toolbar's menu button. You can create a new button with the same icon and use it to popup a menu but it's not that simple.
Remember that the Toolbar is a container and you can customize it the way you want, so my advice is to use it because the other option is a lot harder.
You can set:
in xml
android:elevation="0dp"
or
app:elevation="0dp"
or bycode
getActionBar().setElevation(0);
to remove any elevation of the toolbar.
A few years ago I did something similar to what I think your wanting to do. I made my app so that I had a navigation drawer and settings icon but styled it so that there was no actual visible bar. This gave the app a bit so generic feel and more of a modern look. Also made the drawer and settings menu feel more integrated with the app as a whole. Unfortunately this is a bit of an involved task. For one this in a way, in the sense that they are a "guideline" and that this goes against the idea of making the flow and feel of the app to be what the user is expecting in the traditional sense, goes against the Google Material Guidlines. And two the activity templates are good for learning and generic apps. If your trying to make something that customized is generally going to require you to create everything from scratch. Three, I find I have slight of trouble with the navigation drawer template the Android Studio provides. I'll use it to play around with ideas or to get a feel of how I want my app but if I'm ready to start coding my "production level" app I then start a new project with no activity and make everything myself. Now...
It sounds like what you want is a navigation drawer, which requires a toolbar, but don't want your app name to display. The three simplest solution here would be to go to the strings.xml and in there is a line like so.
<string name:"app_name">YourAppName</string>
Clear that line. (This may cause issues I haven't treated recently and am unable to atm)
There will still be a visible bar across the top though. So if that is not the desired effect, it would be simpler to create a new project with either a black activity or no activity. Google search Android how to create styles and themes and then Google search android navigation drawer with kotlin. Look for a tutorial that shows how to make a navigation drawer from either a blank activity or no activity. Then you will have to create your own style that either doesn't have a color or set the background transparency, of the appbar which is inside/apart of the toolbar, to 100%. I can't remember which because it's been a long time.
I hope this helps.
P.S. Thanks for this question it gives me a great idea for a blog post on my website "How to create a Navigation Drawer with no visible app bar in Kotlin". Once I get it made I'll add a link and can maybe edit my answer with some code detailing the style and theme modifications.

3 dot/settings in top bar buttons

When in some apps, there are those 3 dots in the top right of the app, on the action bar (not the home buttons), which allow for more options. In my app I have on, but I do not know how to make it do a method when it is clicked. Do I use android:onClick="METHOD_NAME ? Or do I need to setup a button variable in my activity class and setup and onClickListener? I have already tried both but I may be doing something wrong.
That three dots are the menu in the action bar. They are always shown on devices without a menu key.
See also the documentation for more details.
Three dots are called Overflow(very aptly named) and to use them you need to use ActionBar which is the top long, horizontal bar showing icons, other buttons along with the Overflow button.
Now in some devices where there is no physical menu button you will always see Overflow button.
Go through Docs and tutorials related to ActionBar but keep one thing in mind that ActionBar is only available for devices with android above HoneyComb. For android devices below 3.0 such as GingerBread or Froyo you will have to use compatibility libraries, so that will be an additional task.
And most notable libraries for this purpose are ActionBarSherlock and AppCompat.

Force to display overflow menu like old option menu

Is it possible to force three dot overflow menu to open from bottom? Just like older option menus - I'm on Android 4.2.2 through ActionbarSherlock.
There isn't a default option to achieve this as far as I know but you could overwrite the standard behaviour.
Nevertheless I wouldn't recommend doing this as the soft home button could be clicked by mistake and thus your application 'closed'.
Additionally you should orient yourself on the design guidelines and as this function is outdated you should use the new one.

Android how to make menu bar that appears at the side of the screen? Like Google Plus, Facebook menu on Android devices

I am developing an app on Android and would like to use the similar menu bar like Google Plus or Facebook, when you click the button, the menu bar will slide in and will not occupy the whole screen. Any ideas on that?
Thanks.
A pretty popular library for accomplishing the 'sliding menu' effect (or 'drawer' as the design guidelines on the Android developer website prefer to call it) is Jeremy Feinstein's SlidingMenu. It's also compatible with ActionBarSherlock, in case your project is using that too. Unfortunately, at this stage there is no component built into the SDK that allows you to do easily accomplish the same thing.
There are also a couple of alternative implementations for a sliding menu (do a search either here on SO or Google), but I haven't checked those out for a little while. If I recall correctly, there are especially some variations in terms of whether the ActionBar is supposed to slide along with the content or stay fixed at the top of the screen.
You can use FrameLayout in parent view and use translate animation in menu layout to show the slide in and slide out effect.

Custom options menu using custom theme and options

I want to create custom options menu as below and also want this to be available on all activities.
So far I am able to add options menu using onCreateOptionsMenu method, and setting its icons.
But have no idea how it can be inflated as shown in images.
After doing some google search found out one example . If can get more help on implementing custom options menu.
Neither of those are options menus. If they happen to be triggered by pressing a MENU button, then those apps are monitoring onKeyDown() for MENU button presses. This also means that their menus will not work on devices that lack such a MENU button.
I strongly encourage you to follow the Android design guidelines. I recommend that you start integrating an action bar and using action items and the action overflow area, perhaps leveraging ActionBarSherlock to support Android 2.x devices.

Categories

Resources