What is use of toolbar and action bar? - android

I am new to android i didn't understand what is the use of toolbar. In place of toolbar we can use any layout like relativelayout then we can design it.
And in toolbar if you want add any button we are creating menu folder and we are doing so many nonsense thing
So inplace of taking toolbar better to take layout.
Please anyone give me the answer why we are using toolbar and actionbar

Toolbars are useful because you can use them in layouts, apply any themes and even create a menu. Toolbars extend viewgroup - that's makes them extra flexible. They are used in layouts to create material designed themed apps. Why does that matter? That's what the users on Android are used to and if you have a custom toolbar you might confuse your potential users. And you get all of this functionality for free, instead of using a layout and manually setting the styles and menus.
So why should you use the supplied toolbar? It's the same with using any component created for use on Android; Don't Repeat Yourself. DRY is the golden rule of software development, and by using these layouts across apps it makes it easier for the users of your apps to understand how to use your apps

It's not an absolute requirement to have a Toolbar, but it has been a staple of the material design paradigm for a while. On many apps, it's used to show the app title, or to house navigation components for example. I suggest you take some time and read the material design rationale for the Toolbar. https://material.io/develop/web/components/toolbar/
The documentation provides some context and suggested usages of the ToolBar in the first sentence of the description.
MDC (Material Design Component) Toolbar acts as a container for multiple rows containing items such as application title, navigation menu, and tabs, among other things.

Related

Is there a way to set up an app bar/action bar in an Android app without going through the appcompat library?

I'm having a "this can't be right moment" trying to learn Android app development. I want to add some buttons to the top bar (app bar, toolbar, action bar, etc) of my Activity. Apparently this thing is called the app bar. But when I read the docs, I feel like I'm taking crazy pills:
This class describes how to use the v7 appcompat support library's Toolbar widget as an app bar.
Why do I have to use something called "appcompat" to add a toolbar? I don't care about backwards compatibility right now, I'm just coding an app to learn. Normally backwards compatibility shims/layers are an optional thing. I just want to do this in the most straightforward way at the moment - it'll be easier for me to learn that way.
There are other ways to implement an app bar—for example, some themes set up an ActionBar as an app bar by default—but using the appcompat Toolbar makes it easy to set up an app bar that works on the widest range of devices, and also gives you room to customize your app bar later on as your app develops.
Again, this sounds like the docs are saying that the method they advocate is not the simplest and most basic way, and that there's another. Then one of the very first steps in the tutorial is:
In the app manifest, set the element to use one of appcompat's NoActionBar themes. Using one of these themes prevents the app from using the native ActionBar class to provide the app bar.
Huh? So the first step to getting a toolbar is to turn off the toolbar? At this point I feel like I can hear clown horns going off. Am I being pranked? I don't think Google realize how bonkers this all sounds to a complete beginner.
Is there a way to add buttons/actions to the default Material UI ActionBar in an Activity, without going through the appcompat package?

Is my approach correct for Android's Material Design implementation?

I have my app UI something like below but with a difference being it's a deck of flash cards.
Now that means I'm making use of material design principles and features. My questions are:
Where should the FloatingActionButton be placed (in activity_main.xml or fragment_main.xml), when the point is to add/remove cards to favourites list, that can be reviewd later.
Where should the TextView element be placed (in activity_main.xml or fragment_main.xml)?
I intend to use ViewPager for swiping cards. And construct the entire UI as part of the fragment_main.xml. And I avoid the temptation of using AppBarLayout and Toolbar; instead use the regular ActionBar.
As I see things this would make code design simple and easy to maintain. Correct?
The best thing to do is to continue taking advantage of fragments for any and all content that is going to share the same layout while also being somewhat independent.
Fragments are reusable, modular bits that can be placed in many activities, For example an Action Bar with an "Add to Favorites Button" used on all Activities can 'live' in its own fragment.
You can define many different Fragments as well, that is, one for the Action Bar named fragment_actionbar and another named fragment_flashcard, each with the needed space and items for information. This gives you further freedom down the road, for example leaving a fragment_actionbar off of layouts bigger than a certain size/density. This will allows you to "make code design simple and easy to maintain."
More on Fragments
As for Material Design, As long as you are taking advantage of the principles taught and shared inline with Material Design, you are following the practice. Broadly, Material Design asks creators to make designs with paper and ink as inspiration, with light, surface and movement being the key drivers to this design approach. Simple Shadows, Bold and Solid Colors, Motion as Meaning, Large Type and utilizing Negative Space are also characteristics of Material Design. Best advise, stick with Androids predefined modules for now and materiel design practices are already being followed/utilized.
More on Material Design

How to implement expandable menu for NavigationView in Android

I was wondering if it is possible to implement an expandable menu for NavigationView like we would use with expandable ListView. Right now i am just clueless where to even start.
The NavigationView is purposely limited, so it it likely difficult to customize it in the way you are asking (but not impossible, as anything can be done with enough effort and hacking).
The limited nature of the NavigationView is by design - it is supposed to be the main navigation control for your app, and be very simple. You shouldn't try to customize it in the way you are asking, and instead see if you can fit your navigation into the existing model.
This is designed to be hard to customize, so you will keep it standard (and your app will stay consistent to Material Design standards).
Bottom line, see if you can fit into the existing model, instead of trying to customize it (and thus be non-standard).

What should be used instead of "setListNavigationCallbacks"?

Background
setListNavigationCallbacks is used to allow the user to switch between different views of the current screen easily via the ActionBar, as shown here and here.
The problem
I've noticed it got deprecated as of API21 (Lollipop), and that all the documentation says is to look for other navigation solutions, but it doesn't say what's the best one that fits the same point:
This method is deprecated. Action bar navigation modes are deprecated
and not supported by inline toolbar action bars. Consider using other
common navigation patterns instead.
All other functions/classes that are related to this function are also deprecated, such as setNavigationMode, OnNavigationListener, ActionBar.NAVIGATION_MODE_LIST .
What I've tried
The navigation drawer is for navigation of different screens, and not different views of the same screen.
adding an action item that will provide a way to switch between the modes, but that's a bit weird...
using a ViewPager, but that's also weird as it doesn't really switch views, plus it takes more space.
Using tabs, but I think that's also deprecated in some way, plus it takes more space this way.
The question
What should be the best alternative to this way of navigation?
This post explains why not only list-, but ALL navigation modes have been deprecated. It became too difficult to make it able to customize Actionbar's navigations. Toolbar is the new Actionbar (also available in the appcompat-v7 support library). However, you won't find these methods there either. Instead, you need to supply your own optional (navigation) view(s). Then you can use it like a normal view in your layout.

Toolbar below ListView

I am working on an application that involves me having to place a toolbar at the bottom of each activity. The toolbar will have 4 buttons on it, each starting new activities.
I am just wondering, and I apologize for how general the question, is there a proper way to go about implementing this? my plan was to but a linear layout element in each xml layout file with horizontal orientation. Then four button elements inside of that...
It seems like a huge amount of work considering I will have a lot of activities..
What you want sounds a lot like Android's ActionBar. Check this link for a guide to its usage. If you use this, your app will look and feel more consistent with the operating system, as so many apps now use the ActionBar (which is a lot of them), and you gain a lot of power for what you want to show there, and how you want to do it.
ActionBar was only introduced in Android version 3 (Honeycomb), but there's a compatibility library, ActionBarSherlock which allows you to use it in older versions of Android as well.
Hope it works for you!
You can use a same xml for various views. So I suggest creating a generic xml, then using Inflaters and other resources as strings, xmls etc. to prepare the generic xml whenever any Activity is loaded. So you can reuse it the xml.

Categories

Resources