I added the following code to the Activity flag and it says that it does not exist.

    ScreenOrientation = ScreenOrientation.Portrait

"ScreenOrientation.Portrait" is the only part that it says does not exist. Do I have to add another reference? Do i have to define it somewhere else? Other forums just said to add the code above. Thank you to those that took the time.

有帮助吗?

解决方案

Using the following Activity flag you can force Portrait orientation for the activity:

[Activity (ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait)]          
public class YourActivity

其他提示

If you want to change activity layout in code, use this:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

The activity's syntax in the androidManifest.xml actually looks like this:

 android:screenOrientation=[
          "unspecified" | "behind" |
          "landscape" | "portrait" |
          "reverseLandscape" | "reversePortrait" |
          "sensorLandscape" | "sensorPortrait" |
          "userLandscape" | "userPortrait" |
          "sensor" | "fullSensor" | "nosensor" |
          "user" | "fullUser" | "locked"]

as it is described at android developers' manifest/activity element: http://developer.android.com/guide/topics/manifest/activity-element.html

To achieve this using xamaring (where you shouldn't edit your androidManifest.xml), you need to add a custom attribute to your class's declaration, to notify the compiler to generate the proper attributes for the <activity .../> tag:

[Activity (Label="MyActivityName", 
    ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait)]
public class MyActivity : Activity 
[...]
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top