1

So I'm basically a total beginner in things of app programming.

I started with the "Navigation Drawer Activity" from Android studio and my problem is, I want the nav drawer toggle icon (top left corner) and the "3 dotted icon" (top right corner), but I don't want it in a toolbar.

My question is, should I remove the toolbar and keep the Icons (if so, how could I do that) or should I make the toolbar fullscreen (don't know how to remove the appname)?

Or is there any better way? Like starting from scratch and placing the icons where I want?

Thanks in advance!

Rhynden
  • 1,297
  • 2
  • 8
  • 8
  • What you want to really achieve? You can set transparent background to toolbar to hide its appearence in layout. – Mohamed Mohaideen AH Oct 16 '18 at 15:34
  • How could I do that? Changing the color of the Toolbar to "@android:color/transparent" doesn't work for me. I want to have both Icons of the toolbar, but not the name of the application and the color. – Rhynden Oct 16 '18 at 15:45
  • [See here](https://stackoverflow.com/questions/26505632/how-to-make-toolbar-transparent) for toolbar background to transparent. & for title https://stackoverflow.com/questions/26648227/remove-title-in-toolbar-in-appcompat-v7 – Mohamed Mohaideen AH Oct 16 '18 at 15:48

2 Answers2

2

What you see as "nav drawer toggle icon" is actually an ActionBarDrawerToggle object and as its name suggests it can only reside in a Toolbar.
The "3 dotted icon" is the toolbar's menu button. You can create a new button with the same icon and use it to popup a menu but it's not that simple.
Remember that the Toolbar is a container and you can customize it the way you want, so my advice is to use it because the other option is a lot harder.

You can set:
in xml

android:elevation="0dp" 

or

app:elevation="0dp"

or bycode

getActionBar().setElevation(0);

to remove any elevation of the toolbar.

forpas
  • 160,666
  • 10
  • 38
  • 76
  • But as I understand the toolbar is a very specific container with very specific uses and it would be bad if I place everything, like TextViews and Buttons in it. Or am I wrong? – Rhynden Oct 16 '18 at 15:56
  • @Rhynden No it's not bad. In fact it's common practice if you want to take control easily of the spacing between the views and different coloring for various views. – forpas Oct 16 '18 at 15:59
  • Mhm, I just don't see the reason to make the toolbar fullscreen, instead of making two Buttons myself? Is it really that complicated to link them to the same action? – Rhynden Oct 16 '18 at 16:03
  • @Rhynden what do you mean fullscreen? The Toolbar is never fullscreen. Yes you can make the 3 dots button but I don't think you can have a navigation drawer without a toolbar (for that I'm not 100% sure) – forpas Oct 16 '18 at 16:06
  • I want a fullscreen application where there are the 2 Buttons, I don't want any toolbar visible at all, so if I dont delete the toolbar or make it transparent, I would have to make it take up the whole screen. – Rhynden Oct 16 '18 at 16:08
  • *I want a fullscreen application where there are the 2 Buttons* so don't set a title for the toolbar and set its background color the same as the rest of the activity and you're done. – forpas Oct 16 '18 at 16:11
  • I tried, thats what Mohammed recommended, then I still had a seam from the toolbar to the rest of the content. I just deleted the toolbar and made an imageview with an onClickListener, seems to work just fine. – Rhynden Oct 16 '18 at 16:18
  • @Rhynden see my edited answer to remove toolbar's elevation. – forpas Oct 16 '18 at 16:22
  • @forpas for the life of me I can't figure out where I would put the XML elevation code to get it to work – sourlemonaid Dec 01 '18 at 20:04
  • @sourlemonaid `android:elevation="0dp"` or `app:elevation="0dp"` in the toolbar's xml – forpas Dec 01 '18 at 20:08
  • @forpas the only problem I run into now, is when i set the background of the toolbar to match the color of the apps background the two buttons disappear as well. though they are still clickable – sourlemonaid Dec 01 '18 at 20:22
  • @sourlemonaid If the color you chose is the dame as the button's this is expected. – forpas Dec 01 '18 at 20:26
  • https://material.io/design/components/buttons-floating-action-button.html might also be an option. – Martin Zeitler Dec 01 '18 at 20:29
0

A few years ago I did something similar to what I think your wanting to do. I made my app so that I had a navigation drawer and settings icon but styled it so that there was no actual visible bar. This gave the app a bit so generic feel and more of a modern look. Also made the drawer and settings menu feel more integrated with the app as a whole. Unfortunately this is a bit of an involved task. For one this in a way, in the sense that they are a "guideline" and that this goes against the idea of making the flow and feel of the app to be what the user is expecting in the traditional sense, goes against the Google Material Guidlines. And two the activity templates are good for learning and generic apps. If your trying to make something that customized is generally going to require you to create everything from scratch. Three, I find I have slight of trouble with the navigation drawer template the Android Studio provides. I'll use it to play around with ideas or to get a feel of how I want my app but if I'm ready to start coding my "production level" app I then start a new project with no activity and make everything myself. Now...

It sounds like what you want is a navigation drawer, which requires a toolbar, but don't want your app name to display. The three simplest solution here would be to go to the strings.xml and in there is a line like so.

<string name:"app_name">YourAppName</string>

Clear that line. (This may cause issues I haven't treated recently and am unable to atm) There will still be a visible bar across the top though. So if that is not the desired effect, it would be simpler to create a new project with either a black activity or no activity. Google search Android how to create styles and themes and then Google search android navigation drawer with kotlin. Look for a tutorial that shows how to make a navigation drawer from either a blank activity or no activity. Then you will have to create your own style that either doesn't have a color or set the background transparency, of the appbar which is inside/apart of the toolbar, to 100%. I can't remember which because it's been a long time.

I hope this helps. P.S. Thanks for this question it gives me a great idea for a blog post on my website "How to create a Navigation Drawer with no visible app bar in Kotlin". Once I get it made I'll add a link and can maybe edit my answer with some code detailing the style and theme modifications.

Vahalaru
  • 380
  • 4
  • 15