9

I just started out with Xamarin. Spent literally a day fixing stupid debugging issues even in VS 2019. Anyways, i guess all the Xamarin devs reading this post already knows how much of a pain in the ar$e Xamarin is.

Anyways, in my Xmarin.Android (Blank) project, i am trying to remove the title bar which says the app/project name(I guess so). So, here's what i'm talking about :

App Header

Please note :

Before i go on saying what i tried, i must add, all of the solutions were found from Xamarin.Forms related posts/forums. I am very confused thinking if i made the wrong choice by choosing Xamarin.Android as it has little to no support available.

What i tried so far :

  • Added android:theme="@android:style/Theme.NoTitleBar" in AndroidManifest.xml

  • Added RequestWindowFeature(WindowFeatures.NoTitle); in MainActivity.cs, inside OnCreate method, before calling base.OnCreate.

The result remains the same. The title bar is always there. However, here's another mysterious bug of Xamarin(Ah, nothing new, right?) i found!

When changing the theme from the designer's top bar :

Top Bar

the changes are reflected in the designer. I mean if i change the theme to, say, Black NoTitleBar, the title bar goes away. But as soon as i launch the app, the title bar pops up in the emulator as well as in the designer.

So, is this the way it is? Are there any Xamarin.Android specific solution for this? Or did i really make a bad decision choosing Xamarin.Android as it lacks support forums?

EDIT 1

When i change the manifest file manually and set android:theme="@android:style/Theme.NoTitleBar", then from the designer, i change the theme to AppDefault, the manifest file seems to remain the same. I mean the theme declared in the manifest file remains Theme.NoTitleBar.

And this is how the Activity attribute looks like :

[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]

Changing AppTheme with Theme.NoTitleBar throws a runtime exception saying No resource found with the given name (Theme.NoTitleBar).......

Update on Xamarin - Update 1.0

So it's been about a year since i posted this question. In this time, i have had worked extensively with Xamarin, both Xamarin Native and Xamarin Forms. So i'm thinking of sharing my views on Xamarin. So let's start with the pros first :

Xamarin Native If you're someone who wants to take freelance projects and wants to handle both the backend as well as the app development yourself, then Xamarin Native is actually a great choice(if you come from the .Net stack). Before you start bashing me, please note that i'm a senior engineer who has worked with android native development in Java, iOS in Swift, cross-platform in React Native along with Xamarin. So getting back to where i was, Xamarin is actually an amazing tool. The Native part of Xamarin is literally no different than the actual Native development. From building you dream UI, to writing the best in-app image caching libraries, to building the best performing app, you can do it all with Xamarin native.

Xamarin Forms Now i've seen a lot of tutorials on Xamarin Native vs Forms and their biggest argument is that you can build native UIs with Xamarin Native but not with Forms. As i've had a great fortune working as a UI designer, i can say for sure that it's an absurd logic to justify using Xamarin Native. Even in Xamarin Forms, you can build the best looking UI. From freelance to enterprise projects, if you want to save a lot of money and if you want an amazing looking app with a great REST API supported backend, all powered by C#, Xamarin Forms is the best way to go. There's literally no arguments on that. If you want to put forward any arguments, i highly suggest you to point to some data as well that support your arguments.

Anyways, as i mentioned the pros in a short manner, let me talk a bit about the cons(Yeah, i know, the non-C# community should start smiling by now). So here're the top cons of using Xamarin, both native and forms:

  1. You don't fix your bugs, but rather the bugs that already exist there

My my! This is the biggest pain in the b**t! If you're someone who started off with Xamarin two years back, in Visual Studio 2017, i think you can relate the most to it. I literally had to spend countless hours just to get a "Hello World" app running, because guess what? I had to fix the bugs pre-existing in Xamarin. Now don't get baffled with the fact that Visual Studio is the best IDE so it can point out where the bug is coming from. Believe me, IT CAN'T!!!.

That's not the worst part tho. The worst part is, even the Xamarin community can't help you! How can they, if they don't actually exist lol ? ... which brings me to the next point :

  1. A community so small that you literally need glasses to see!

Sorry to put it that way, but this question is about a year old. How many well-written answers do you see below? I see 2 answers with little to no explanation unfortunately! Well, not to hurt the feelings of those who answered, but that's the truth. Even if you seek help on Xamarin's official site, you'ld be lucky even to get a response like "Can you post the entire exception log ?". So with a very small community, on an initial stage, you're literally on your own :(

  1. Millions of libraries, yet not the useful ones.

Yes, with C#, you get access to a billion of libraries. But when it comes to native Android and iOS, Xamarin literally makes you feel handicapped :(

I remember that i once needed something similar to Picasso for image caching but the best option Xamarin had was FFImageLoading. The library is good but not even close to Picasso. The first time i installed and ran it to get a number of images from the web, it crashed my entire app, without even pointing to what caused the crash!!... which brings me to :

  1. It's not just you, but even the IDE is clueless

Yes, when your app crashes, the IDE just shows you the tip of the ice-berg :( You are thrown ambiguous exceptions like Java exited with code 1 and bla-bla! But when you ask the IDE what caused it, the IDE be like : "Meh, i don't know dude. What is google for?". Then you run to google. You search up the issue and you see that it is literally related to something that you haven't even touched yet! But guess what actually fixes the issue? Remove the last library your installed or remove the last line you wrote and wallah! it works again!!!

Now i guess i've talked enough and it's time to encourage you to use Xamarin. Let me give you some tips i followed, which will definitely help you be on track with Xamarin :

  1. Search issues with Android Java, not with Xamarin.Android

For the most cases, you can find the best solution by typing your issue in google and instead of mentioning "in/for Xamarin.Android" use the term "android java", because that's what Xamarin compiles down to. The Native android has a much bigger community, so you have much higher chances of finding your solution! Yes, sometimes you'll find Java code that you'ld have hard time to find the perfect C# syntax for, but the xamarin community on the official Xamarin site has most of it written out, in their answers, for you. So once you get a java code you don't know how to write in C#, just search up the line of code and add "Xamarin" in the end of your search query.

  1. Use Android Studio and XCode for design

Never ever, i repeat never ever, use the Xamarin designer, specially on Android. It is so misleading that even if you write a correct syntax in XML, it shows you red lines, and when you actually actually write something wrong, it complies perfectly but crashes on launch(or on the specified screen) leaving you mostly clueless. So always use Android Studio and XCode for designing. Create the drawables, reference them in your fragments or views within Android Studio and create your dream design. When all is good, just copy paste the files/codes in them back to Visual Studio and it'll save of tons of headache and time! However, the Xamarin iOS designer does seem to work a bit better than the android one. But whenever it throws you some random error, just copy paste the code from the .xib or storyboard file and open it in XCode, you will have much better understanding of what's going on!

  1. Clean, rebuild, launch, crash, restart PC, clean, rebuild, launch success!

Yep, that's the secret 99% newcomers don't know! But i hope you know it now ;-)

  1. Build your own libraries

Yes, i know you found the best library you've been looking for and it has a million+ downloads, but if it makes your app crash unexpectedly, it's time to write your own library! It's not gonna be optimal, but it'll help you sharpen your coding skills and you'll have full control on what's going on. And this advice is coming from someone who had to spend a week writing an amazing image caching library for not just Xamarin but for any platform powered by C#(I'm thinking of releasing on the Nuget store someday).

  1. Use the latest Visual Studio

Spend your time and download the latest Visual Studio(2019, at the time of writing this) with all the latest updates. VS 2019 has tons of bug fixes for Xamarin and even the designers work pretty well now! So go on, update!!

Oh, and for the bigger question: Why use Xamarin Forms instead of React Native or Flutter or anything else?

Well, the one line answer is : With Xamarin, you only need to write C#, with others, you end up writing a lot of Java and Swift code.

Anyways, let's talk a bit about THE FUTURE!!

So, to be honest, Xamarin never led the market. You will find some big apps built with Xamarin but the numbers are small! But if you don't judge a technology by the number of projects it powers, then you'ld understand that Xamarin is actually a game changer! You can build anything and everything with it. However, i'ld still suggest you try out React Native or Flutter, because if you know multiple technologies, you have better knowledge of what to choose when, under what circumstances. So best of luck for your future! Pick your tech and start rocking!

Cheers!!

10
  • Xamarin.Android wraps the Android framework, aside from the the code syntax differences of C#, Java or Kotlin and the C#-afication that Xamarin does to the framework calls, a solution in Java|Kotlin|C# all work the same way. When it comes to layouts/themes/etc... this are language agnostic. Edit your question and add your manifest changes and the C# attributes your C#-based actvitity is using. Apr 4, 2019 at 15:59
  • @SushiHangover, i am not sure exactly what kind of an edit you are suggesting... can you please elaborate a little bit? Apr 4, 2019 at 16:00
  • You stated you changed the manifest manually, show those changes in context within your manifest as did you change the application level theme? or the activity level theme?, are the changes correct?, .... Also Xamarin.Android also supports assembly and class level attributes that effect the manifest during build time, add your activity attributes to your question as themes also are applied there and thus are they overriding your manifest based changes, etc... Apr 4, 2019 at 16:04
  • @SushiHangover, check my edit Apr 4, 2019 at 16:14
  • 1
    @Aousafrashid damn man, you speak to my heart :P you point out so many probllems i had, im a freelancer in al my life, i work alone and i was never able to understand if Xamarin is bad or me because i havent worked in a enterprise environment, i have exactly the problems you talk about, and the bugs, and some of them i fixed them with vs support team, and the layouts is the last think i want to design, i was thinking of hire someone for the design :P i will use your solution now. i already use Android Studio for launcher icons, a ton of thanks to you, your answer is super helpful to me
    – CDrosos
    Aug 9, 2020 at 12:28

6 Answers 6

5

Hmm, so it was a one line fix after all?

Anybody struggling with this issues: The following change in the activity class MainActivity.cs fixed it :

[Activity(Label = "@string/app_name", Theme = "@style/Theme.AppCompat.Light.NoActionBar", MainLauncher = true)]

You can set other themes as well, i guess. After all, you are the UI master!

2
  • Is it possible to not have the themes available? I created a new Android WebView app (I'm using VS for Mac 8.10.6) and when I try what you suggested here I get this: .../Properties/AndroidManifest.xml: Error APT2260: resource style/Theme.AppCompat.Light.NoActionBar (aka TestApp.TestApp:style/Theme.AppCompat.Light.NoActionBar) not found. This error is likely caused by an issue with the AndroidManifest.xml file or an Android manifest generation attribute in a source code file. (APT2260) (TestApp)
    – Dan Sharp
    Aug 9, 2021 at 2:57
  • 2021 This does not work anymore Sep 23, 2021 at 9:16
1

[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

This work for me

3
  • Hi, please explain how your code helps fix the issue, instead of only posting code, so that others may understand as well. Aug 21, 2019 at 18:24
  • Theme = "@style/AppTheme" Theme is mandatory in the main page so we are setting NoActionBar to the theme in styles and calling that style in main page
    – sohail sk
    Aug 22, 2019 at 19:59
  • For anyone wondering, I found the style tag under Resource/values/styles.xml in my project
    – Roy Zwart
    Jun 26, 2021 at 20:22
1

Tip for "new" Shell navigation. Try

Shell.NavBarIsVisible="False"

For the shell xaml page and child pages of the shell page. Actual answer from microsoft docs questions: https://learn.microsoft.com/en-us/answers/questions/349760/how-to-hide-navigation-bar-on-xamarin-forms-when-u.html

0

There are two methods to hide title bar in Xamarin.Android. One is already mentioned by Aousaf Rashid by using styles The other simple method is:

ActionBar.Hide();

in the oncreate method in activity

0

This answer is applicable for applications using shell.

In content page class in which you want to hide Title bar -

    protected override void OnAppearing()
    {
        base.OnAppearing();
        Shell.SetNavBarIsVisible(this, false);
    }
0

You most edit "Resources\values\styles.xml"

Add a New style With Following "parent" property Or Update The Default "AppTheme" With This: parent="Theme.MaterialComponents.Light.NoActionBar" styles.xml If you add a new style you most change it in your Activity.cs file Activity.cs

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.