1

I have been searching on how to create a native top bar in Unity with menu item for Android mobile game (the 3 vertical dots and the back arrow) but I couldn't find anything.

So I was wondering if there is a standard Unity way to create a top bar like the native Android or I have to create a custom one?

Here is an image with what I am describing (yellow color is all the bar, and red color the 3 vertical dots)

enter image description here

Thank you.

Johny
  • 625
  • 2
  • 6
  • 26

1 Answers1

1

There is no standard Unity way to create a top bar like the native Android. You have to create a similar UI that looks that the Android menu with the components Unity's UI system This can easily be done if you know the basics of Unity's UI system.

Breaking down the Android menu for Unity:

  • The three dots can just be represented with the Image or RawImage component. If you decided to have 3 images(one for each dot) instead of one image with three dots then use the VerticalLayoutGroup to group all dots into one.

  • The search icon could just be a UI Button, Image or RawImage component.It really doesn't matter. Any of these should work.

  • You will need a grey background image just the color from the Android Menu Item. Again, this image will also use the Image or RawImage component.

  • You will also need a Text component to show your "Action Buttons" text or any or text you wish to display in the menu.

  • Finally, group all the components mentioned above into a panel then use anchor and pivot point to position the panel to the top of the screen.


If you still want to show the Android menu, it is still possible to do:

  • Create new Android project with Android Studio (Not from Unity. From there, create the Android menu item.
  • Export your Unity project and import it into your Android project in Android Studio.
  • Modify your Manifest and Activity class code to display your Unity game as sub-view. You can find more information here. From there you can even call Unity's function from your Android project with the UnityPlayer.UnitySendMessage function if needed. Your game will run with any Android UI.

I don't recommend this because it would only work on Android. Also, each time you make changes to your game, you would have to export it again. This is annoying and time consuming. Use the Unity UI system to create this.

Programmer
  • 121,791
  • 22
  • 236
  • 328
  • 1
    That's what I had in mind, that there is no standard way and I need to make a custom one that will look the same so I just wanted to check if there was a possibility. Thank you for the detailed answer, it helped me understand more about Unity now. – Johny Nov 28 '18 at 10:25