Xamarin Cross-Platform and "Native" Codes

Asked

Viewed 41 times

0

Good morning,

I recently started a study on multiplatform development, and now I’m evaluating Xamarin (Visual Studio 2017), but I’m having difficulty with some questions. The main one is the possibility to overwrite the "common" class with native codes, I’m trying to configure the initial Activity to remain PORTRAIT on Android, I found the code for this.

[Activity(Label = "App2", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Portrait)]

But it doesn’t apply to my application when I run it, in fact, nothing I do in Activity seems to affect the application. Is there a process that may be missing? It is necessary to link Activity (Mainactivity) to CS "common"?

The question, to summarize, what is necessary for Activity (Android) to impact the application if it is run on this platform?

I researched horrors and haven’t found anything about it yet, any light would be welcome, a tutorial, a starting point, anything. Even if in English.

  • I don’t quite understand, what you’re looking for is #if __ANDROID__??? https://docs.microsoft.com/pt-br/xamarin/cross-platform/app-fundamentals/building-cross-platform-applications/platform-divergence-abstraction-divergent-implementation

  • No, it is that in the part of android there is a Mainactivity, and for me to leave it with guidance only Portrait need to make this change of question, the point is that even making this change nothing happens, even if I clean the code of Activity nothing happens, as if the app was ignoring this Activity. What I’d like to know is if there is any process to accomplish that makes the app consider this Activity, which is the default when creating the Xamarin project in VS2017

1 answer

0

Try to go in the manifest file and set the orientation for what activities you want:

<activity android:name=".MainActivity"
    android:configChanges="orientation"
    android:screenOrientation="portrait"/>

android:configChanges tells Android that you are responsible for the orientation changes. android:screenOrientation="Portrait" configures your orientation pattern for portrait.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.