Controls showing in designer but not in emulator

半城伤御伤魂 提交于 2020-01-11 07:20:45

问题


This is my first Xamarin app. I have my environment set up in Visual Studio, and have a template project which I can run in the Android emulator.

Having dragged and dropped a couple of controls on to the designer surface, I find that when I run the application in the emulator, neither of the two controls that I have added (a button and a switch) display in the emulator.

I have tried:

  • Cleaning the solution
  • Rebuilding the solution
  • Manually deleting bin and object files
  • Unchecking 'Use Fast Deployment' in project Android Options
  • Uninstalling from the emulator

But with the same result each time.

[Project files removed]

Am I missing something?


回答1:


Just downloaded your code and ran it. Uncommenting SetContentView (Resource.Layout.Main); it worked to me.

[Activity(Label = "Tgo.AndroidApp", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView (Resource.Layout.Main);
    }
}

Here a nice guide to get you started with Xamarin Android.




回答2:


navigate to MainActivity.cs and uncomment this code

SetContentView (Resource.Layout.Main);

and rebuild the solution and debug.

Let me know it if helps!



来源:https://stackoverflow.com/questions/41990579/controls-showing-in-designer-but-not-in-emulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!