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?
Related
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.
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
I am using navigation drawer with fragments.
Generally, I want the fragments to change the activity's toolbar title.
When starting the app, I supply a default fragment by using fragmentManager replace method.
But the fragment can't change the title of the activity's toolbar.
On the other hand, when changing fragments after App is started, it can change the activity's toolbar title
Can someone elaborate on this?
Thank you
Best regards Morten
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.
So I'm working on adding ActionBarSherlock and the Navigation Drawer to a project that previously implemented a custom (very poorly written) "action bar". Instead of using fragments and a backstack of activities for navigation, some activities show and hide different layouts. (That is, suppose I am in a list mode and then select a button to go into an edit screen. The app currently hides the list layout and shows another layout.).
So I've added actionbar sherlock and a navigation drawer to all the activities. I want to be able to programmatically switch the navigation icon from the 3 lines to the arrow when certain buttons are pressed.
I can't figure out how to do this though. Any ideas?
Thanks!
The solution to this problem is to use the method:
setDrawerIndicatorEnabled(boolean enable)
inside the ActionBarDrawerToggle class.
After:
drawer.setDrawerListener(toggle);
Use this code:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.select);
It depends how wedded you are to built-in actionbar artifacts. You can always redraw the current actionbar by inflating a layout of your choosing, then calling
getSherlockActivity().getSupportActionBar().setDisplayShowTitleEnabled(false);
getSherlockActivity().getSupportActionBar().setDisplayShowHomeEnabled(false);
getSherlockActivity().getSupportActionBar().setDisplayShowCustomEnabled(true);
// Inflate and do whatever you need to your view...
getSherlockActivity().getSupportActionBar().setCustomView(abView);
getSherlockActivity().getSupportActionBar().show();
When you want to go back to your standard (assuming you're using a DrawerLayout to do your navigation drawer), you can just set make a call to setDisplayShowCustomEnabled(false) (re-enable showHome and showTitle as you please).
As far as I know, customization of the back button can only be done via themes. Besides, swapping the drawer icon for the back icon (within the same Activity) doesn't make sense, since users would still be able to access the navigation drawer by sliding the left most edge to the right. It just wouldn't make sense.
If you absolutely need the back icon, then it would make the most sense to make that screen a new Activity since you would indeed be adding another "level" to the stack, which is what the back icon represents.