Now I have my nifty custom title bar in its own XML layout file and I've got my custom theme and style XML files. From my Activity class I can invoke it and it looks great.
Problem is my app has 14 Activities, each with their associated layout file. If I want to see the same title bar appear across my app, i.e., in all my Activities, the two main strategies I've seen are:
Put a an <include layout="#layout/my_title_bar" /> for my title bar in every layout file
...or...
Change all my Activity classes to derive from some common Activity that invokes the new title bar
Before I go off and do one of these I just want to make sure there's no more "centralized' way of doing it, like, say, in the manifest. There's no need to declare the default title bar in every activity, and it doesn't seem right to have to make separate changes for each activity for an app-wide feature like a custom title bar.
Thanks in advance for any tips!
Related
I have a simple app with just one activity. I'm trying to hide the navigation bar from the landscape version of the main activity's layout file.
I tried to find the specific attribute in AppCompat theme and create a custom style that would hide the bar from my layout but haven't found anything matching my goal. I know that it can be done in my activity's class code but I wonder if this is possible to set up in the layout file.
No way, you can hide navigation bar from swipe gesture in setting device.
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.
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 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.
I want to have an static bottom menu bar exist through out the applications in every page visible at bottom all the time. I have designed the menu bar but i am confused whether i have to integrate the menu code with every layout xmls to make menu visible in every page and write the code in every activity class to perform functions on menu clicks. Or if there is any other way i can create a common bottom bar that lies with every page with writing the code of menu in a single activity class.
Well the best way in my opinion , is to create a bottom bar xml file , and include it in every Activity's xml file
<include android:layout_width="fill_parent" layout="#layout/bottom_bar" />
where your bottom bar xml file name is bottom_bar.xml
This article also might help you
http://android-developers.blogspot.com/2009/02/android-layout-tricks-2-reusing-layouts.html
There is also the include route:
Common layout in all tabs
What you are probably looking for is one Activity with a TabBar with tabs at the top and buttons at the bottom: Android: Tabs at the BOTTOM
Then you can use different Views that correspond to Tabs instead of separate Activities.