Hide Toolbar from Activity and custom toolbar in fragment - android

I want to hide toolbar in my fragment and display my own custom toolbar for that fragment.
ps. i have darkactionbar in styles.xml. after hiding and showing my own custom toolbar, here is the images. please help me out in this.enter image description here
before navigating to fragment - image 1
on fragment - image 2
closing fragment and returning to activity - image3

There are multiple ways to hide the inbuilt toolbar -
Let's talk about all steps for Kotlin code:
If you want to hide toolbar in Activity you can use -
actionBar?.hide
If you want to hide toolbar in Fragment you can use -
(requireActivity() as MainActivity).supportActionBar!!.hide()
Another way is to change DarkActionBar to NoActionBar in your themes.xml
Now these were the ways by which you can disable inbuilt toolbar.
Next is to see how to create your own toolbar.
So simply in MainActivity xml create your design and add clicks to it in kt file.

Related

Custom Toolbar in Navigation Component

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

how to change a empty toolbar present in main_activity.xml file with home_toolbar.xml on clicking a specific fragment. Please help, I'm new to android

My main activity
Activity.xml File
This is my Home Fragment.java File
I want to load this toolbar inside my main activity default toolbar
I don't know if i get it what do you mean, but if i understood it should be better to place the toolbar inside the fragment and in the default toolbar you can take that off in the manifest archive.
android:theme="#style/Theme.Application.NoActionBar
So in each fragment, you will have to put another toolbar if you needed
Creating Contextual Menus
https://developer.android.com/guide/topics/ui/menus

Is possible have to different menu in Action Bar? (Kotlin)

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.

Hiding toolbar title only for one fragment

In my app I want to remove toolbar title for one fragment only. When I use the following code
((AppCompatActivity)getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);
it also removes title from all other fragments too. Is there any other way to remove title for only one fragment and keeping it in others. I also tried removing title attribute from navigation drawer implementation but then it starts showing app name in title. I don't want anything in this fragment . How this can be done?

Android: How to remove title padding when using sliding tabs toolbar

I am following this tutorial. The tutorial basically helps to create a sliding tab menu by using the AppCompat library. It basically creates a custom toolbar using the tabs and then replaces the standard ActionBar with this toolbar.
It works perfectly, but I do not wish to show the title. I only want the tabs at the top of the screen to be my main navigation. On my activity I have set
getSupportActionBar().setTitle(null);
but this only makes the text for the title blank. Space (padding?) is still reserved for the title. How do I remove it?
The picture below shows the problem visually.

Categories

Resources