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 :
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);
inMainActivity.cs
, insideOnCreate
method, before callingbase.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 :
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:
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 :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 :(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 toPicasso
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 :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 likeJava 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 :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. TheNative
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.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 thedrawables
, 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!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 ;-)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).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!!
6条答案
按热度按时间ubof19bj1#
嗯,所以这是一个行修复毕竟?
任何人都在纠结这个问题:活动类
MainActivity.cs
中的以下更改修复了该问题:你也可以设置其他的主题,我想。毕竟你是UI大师!
1l5u6lss2#
[活动(标签=“@字符串/应用程序名称”,主题=“@样式/应用程序主题”,主启动器= true)]
这对我的工作
ghhkc1vu3#
“新”Shell导航提示。尝试
对于shell xaml页面和shell页面的子页面。来自microsoft docs问题的实际答案:https://learn.microsoft.com/en-us/answers/questions/349760/how-to-hide-navigation-bar-on-xamarin-forms-when-u.html
to94eoyn4#
在Xamarin.Android中隐藏标题栏有两种方法。一种是Aousaf Rashid已经提到的使用样式。另一种简单的方法是:
动作栏.隐藏();
在活动的oncreate方法中
ffvjumwh5#
此答案适用于使用shell的应用程序。
在要隐藏标题栏内容页类中-
j2qf4p5b6#
您最多编辑“资源\值\样式. xml”
使用以下“parent”属性添加新样式或使用以下内容更新默认的“AppTheme”:parent=“Theme.MaterialComponents.Light.NoActionBar”
如果您添加了新样式,则最好在Activity.cs文件中对其进行更改