I have used Google's solution for multiple back stacks in Navigation Component. I want to setup a custom AppBar at the activity level(Idea is to have a Toolbar, A FragmentContainerView, and BottomNavigationView)
This works fine except this sets the title of the Toolbar automatically (doesn't call any particular method in the file I have linked as far as I know) .
I want to build a custom toolbar which has a TextView with multiple colors(As in half of the title is black , other half is yellow).
Any solution how to build a custom toolbar in this solution would be greatly appreciated
You can read this document about handle navigation component back stack with appBar configuration
https://developer.android.com/guide/navigation/navigation-ui
and also you can watch this course for make custom toolbar
https://m.youtube.com/watch?v=e5_C9e_gKOM
Related
If there is a toolbar, it is usually passed into setSupportActionBar(). Why?
As per docs
A Toolbar is a generalization of action bars for use within application layouts. While an action bar is traditionally part of an Activity's opaque window decor controlled by the framework, a Toolbar may be placed at any arbitrary level of nesting within a view hierarchy. An application may choose to designate a Toolbar as the action bar for an Activity using the setActionBar() method.
But in simple ways, this is a way of telling the Activity that you are interested in using the features related to Toolbar. It will delegate the functionalities related to your defined toolbar. It helps activity to understand the many of the requirements some of them mentioned below.
1) Setting menu options
2) Setting Navigation drawer
3) Setting common Toolbar
4) Setting back button on the top left
5) Using an icon for brand identification
6) Setting a common title or subtitle
7) And many more
If you don't mention for these functionalities by telling the activity using setSupportActionBar then you have to create all this by your self and support them back to the older version. With Toolbar it comes free and you have to just tell a activity to use it will take of supporting different functionalities itself.
if you want to apply your custom toolbar instead of default toolbar then to set toolbar into that specific screen/activity you must be use setSupportActionBar() along with your toolbar. ;)
I am new to Android development I am building an app but from last three days, I am stuck while making toolbar I am very confused. I want to make toolbar like this
The widget elements in your design are the following from left to right:
Navigation Drawer Indicator
ImageView
SearchView
Toggle
Overflow Menu
These can all be implemented using default widgets. It is not common to put a profile image to the right of the title, but you could do this by putting a custom layout inside the toolbar view.
It is also not common to place a toggle in the action bar, but it is possible using an ActionLayout.
I've been interested in material design and wanted to build a layout for the main page of my app so that it looks like the default template for Scrolling Activity but also has a Navigation Drawer like the default template for Navigation Drawer Activity for easy navigation.
As an example, Google's Play Music app already does this sort of thing.
Have a look:
Scrolling list with a banner and a FAB at the top,
Navigation Drawer, accessed by swiping from over to the left
I've searched everywhere and could find a direct way for implementing such a layout. So I tried doing it on my own and with some changes here and there in the default templates of Scrolling Activity and the Navigation Drawer Activity I was able to achieve something along those lines but not exactly what I was looking for.
I was hopping if someone could present a better way of doing it.
You can still use the DrawerLayout supplied in the Android support library with a FrameLayout and ListView to achieve the Navigation drawer. In the FrameLayout, you will display a Fragment which takes a ScrollView to display scrollable content. The Fragment can also have other widgets that let you customize your layout.
I've got exactly what I wanted, you simply need to include Scrolling Activity's layout inside the layout of Navigation Drawer Activity and it works nicely.
You can use the default templates for these activities given in the Android Studio to save yourself some time or start from scratch.
Let me know if anyone needs some code and I will be more than happy to post it :)
My question is how do I do make the ActionBar transparent (and also the status bar)?
I'm having trouble trying to make use of the AppBarLayout and Toolbars on Android to achieve that.
I need that because I want to create an application that has one main Activity that holds a DrawerLayout and many screens which are mostly fragments. Then, there is some screens where the ActionBar and StatusBar becomes transparent (while still having the hamburger button for the DrawerLayout).
I've tried changing the AppBarLayout and the Toolbar, but it looks weird... It looks like there are some weird margins on the ActionBar.
appBarLayout.setBackgroundColor(ContextCompat.getColor(this, android.R.color.transparent));
toolbar.setBackgroundColor(ContextCompat.getColor(this, android.R.color.transparent));
And here is the result:
And here is it before changing the color/changing it back:
Any ideas on how to achieve the transparency on the ActionBar when some fragments are attached to the main content of the main Activity?
If you want to take a look at the code, here is the repository: Sample Repo.
Okay...
I made a mistake here...
First, all you need to do is remove the paddings on the content_main.xml and set the elevation of the appBarLayout to 0 and the code will work. (You'd need to set it back to its original value if you need the shadows).
I updated the repo to fix that and it should be working now.
But, There is another way to solve this problem using a fragment with its own AppBarLayout/Toolbar and hiding and showing the MainActivity AppBarLayout when you're showing the Fragment inner one.
I'll create a branch in the same repository to show what I mean.
Please, answer/comment with better solutions/ideas if have them.
Repo here.
I've read this question and watch the video clip from Bitspin, however I'm still unable to figure out the techtique they used on ActionBar.
You can observe the ActionBar layout transition inside Timely, when navigating from the settings Fragment to the about Fragment (and navigating back), the up caret and the title is animated by zooming and fading. So how is this made possible?
Or can you let me know if there is some techtique on crossfading ActionBar layout changes? My main purpose is to smooth the transition when user opens the navigational drawer and the title changes, aciton buttons disappears.
Thanks in advance.
EDIT:
I turned on the dev options for showing layout borders and found that Timely is using custom layouts to achieve this. However this is not possible for other applications heavily relying on other ActionBar features such as ActionMenu.
So are there any alternative ways to achieve layout transitions on ActionBar and its ActionMenus?