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.
Related
Im making an app for android, without actionbar.
What is best practice for showing titles without actionbar?
The best practice is basically never using an action bar. This gives you a complete device screen to play with.
You can use images or different text styles for showing the title. You can also use interesting icons.
To remove action bar -
Go to res > values > styles.xml
Here is an illustration of styles file -
You can use the Toolbar (it's like the action bar, but more flexible). For example, action bar needs to be on top of the screen, but toolbar can have place anywhere in the layout.
You title can be shown as text or a beautiful asset.
If, for some reason, you don't want to use the toolbar, you can think about something like having a scrollView with the title on top of it.
Use a regular LinearLayout with a TextView inside. Style according to your needs, and set the text in the xml, or programmaticaly using TextView's setText() method.
So, if you build an app in Android Studio, you can of course use ConstraintLayout. I set the constraints, but often find that when I actually launch the app, the content is under the title bar at the top. But the title bar isn't apparently something you can access while designing (either in Design or Text view of the layout).
Is there a good way of avoiding this? Making sure that you don't overlap the title bar on devices?
Yes, use fitSystemWindows flag or xml property in main view.
I want to make android custom app bar that contains searchbox, icon, etc.
The solution on google that I found was changing the style to no action bar. And create a toolbar layout that need to be included in every activity I made.
I just wondering, can I make custom App bar that default appear in every activity without including them when creating Activity?
I would recommend using v7.widget.toolbar. At first you need to create custom layout for your toolbar. Then you need to set it as a support action bar in each activity that you want it to appear. Toolbar on every activity can contains different icons.
https://developer.android.com/training/appbar/setting-up.html
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 want to set a footer in android fragment. I am using appcomat for action bar and would like to have a bar simialr to action bar with as footer.
Footer will display some information as text .It wont have any clickable buttons.
I have create a mockup of footer as shown below.This will then contain some text.
Note the color of footer should be same as action bar.
Also the UI looks very ugly.How can i make it better?
answering my own question : I found the following way better.
Use nested layouts
Android: 2 relative layout divided in half screen