I have an app, which have an action menu item on the right (2).
I need an ulterior menu in the left(1) or a button in the action bar, is that possible?
I attach a image.
enter image description here
You may create a custom toolbar. The standard height of a toolbar is 89dp.
To create a custom toolbar you should make your activity view container RelativeLayout. Then create a custom toolbar view (it may also be RelativeLayout) which height is 89dp. Then add your toolbar to the main container and set alignParentTop to true. So you have a custom flexible toolbar and you can add any view to it.
This way is very comfortable to use any custom views on your toolbar.
I also faced the same situation of customizing action bar. After a lot of searching I got the solution which is Toolbar.
Checkout: https://developer.android.com/training/appbar/setting-up
I think from now on, you should start using Toolbar as the default action bar for your apps. It provides high level of customization and material design features.
Related
I am newbie in android app developing and learning android UI design.I am trying to make a toolbar like below image.But i don't now what is the xml code for below image toolbar.
Two options. Personally I'd go for the first.
Overriding the view
First approach is overriding the default toolbar / action bar. This has the advantage of being able to use AndroidX navigation, automatic back stack navigation, etc, with the disadvantage of a bit less control.
All you need to do is enable custom views on your action bar, apply a custom view, hide the default title, then set the elevation to 0 so there's no shadow. This will be something like:
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(R.layout.your_custom_layout);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.elevation = 0f;
R.layout.your_custom_layout can then be whatever layout you want, so long as it fits in the same space. I've written a full tutorial on this previously, as well as a sample project in Kotlin.
Defining your own
The second approach is ignoring the built in toolbar / action bar, and just rolling your own. This gives you full control, and allows setting the bar to any height, but you lose all built in functionality. For this, just use themes without a toolbar, and draw your own bar (perhaps in an activity that then swaps in fragments).
I'm looking at the toolbar at the top here:
http://cdn1.tnwcdn.com/wp-content/blogs.dir/1/files/2013/10/digg11.jpg
Does anyone know what the icon on the top left is called and where I can find it? Also, is there anyway of adding this to my toolbar without using an ActionBar? For some reason ActionBar is deprecated for me and I have all sorts of trouble following tutorials since they all link the toolbar with ActionBar.
Appreciate any help!
you should use the action bar for that and just lay the background to the same color of your Activity background so it gives the illusion you have no Action bar. but if for some reason you insist in doing it without an Action Bar then use an image view and align it to parent top and to the left side.
And Just change your extends to AppCompatActivity so you can see your Action Bar
I need to develop a custom layout for the action bar in Android.
I'm now stuck because I have no clue how to calculate the available space for my custom layout.
In the image, the red part is my custom layout, the blue part is the space occupied by the action buttons.
Clearly I need to know/calculate the size of the red part to be able to correctly position the elements in my custom action bar (for example center the title in the window or make sure not to overflow in the blue part).
How can I achieve this?
I couldn't find useful examples or a clear API in the Android documentation.
I think that anyone using the custom action bar layout must be facing this kind of problem, I'm a bit confused.
Or am I supposed not to use action buttons in this case? Perhaps I'm supposed to replicate the action buttons by myself?
Thanks in advance
Try using ToolBar instead of ActionBar. It will give you a lot more control over ActionBar elements than ActionBar.
Here is a simple tutorial about how to replace ActionBar with ToolBar and how you can customise it.
Material ToolBar
Possibilities are endless with ToolBar but my recommendation is to don't overdo anything.
As per my suggestion try to use the entire action bar by your custom layout. So that you can arrange all the things use it as a fragment inside a framelayout for all your screens so that the code can be reused for all your layouts.
I have a similar problem as found on this specific question.
I'm using a Toolbar from the v7 support library, and a custom layout. If I have no options menu, I have a result similar to what OP has on the question linked above:
However if I have an options menu, it shifts the toolbar a little bit to the left (start). I would like to have it over the toolbar.
Is it possible? The only way I could hack it is by adding a negative right (end) margin to the toolbar layout, however this moves the menu outside of the screen…
Initially, the whole Toolbar contained several views, so they had to share the width with the action menu.
Now instead I wrapped the Toolbar and the other views in a container (a FrameLayout), so that they overlap without sharing the width. I just need to be careful with the margin at the top so that the other views don't overlap with action icons.
I recently thought of adding a custom title bar to my app (with "find me" and home button and such) and then I thought what is the reason of using a custom title bar at top instead of just a normal layout and using it as an include tag at the top of my XML's
What are the pros and cons of each? Is there realy a difference?
EDIT: one difference ive found so far is that the custom title bar has a shadows automaticly
For having back and home button titlebar, you should define normal layout for the same. Because it is easy to implement as compared to customized the native title bar. And we can create normal layout as we wants with any color/height/width/image backround/etc.
I suggest you to go with defining normal layout for the title bar instead of customizing the native title bar.
You can extend LinearLayout to create a new layout with your title bar. The advantage is you can then customise the title bar for different activities that use it. Some may not want to display the find button for instance.
If you use include in XML you don't have the same flexibility.
I would create a custom layout with the title bar.