1

I am unable to set the View Size matching the Display Size, below is the code, it is a Transparent View

 TestView testView;

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        testView = new TestView(this);
        SetContentView(testView);

    }

The Default Height of the View when the app runs is height=1206 but the Display Height is 1280, i have used the following methods to set the View Size match the Screen Size, but none works

Does not work

protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);

    testView = new TestView(this);
    IWindowManager window = null;
        window = this.Application.GetSystemService(Context.WindowService).JavaCast<IWindowManager>();
        Display defaultDisplay = window.DefaultDisplay;
        DisplayMetrics display = new DisplayMetrics();
        defaultDisplay.GetRealMetrics(display);
        int width = display.WidthPixels;
        int height = display.HeightPixels;
        RelativeLayout.LayoutParams parms = new 
                       RelativeLayout.LayoutParams(width, height);
        testView.LayoutParameters = parms;
    SetContentView(testView);

}

Result:

enter image description here

Doesn not work:

protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);

    testView = new TestView(this);
    SetContentView(testView);
    if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
        {

            Window.SetFlags(WindowManagerFlags.LayoutNoLimits,
                              WindowManagerFlags.LayoutNoLimits);
        }

}

<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>

Result:

enter image description here

How to set the Display height to the View?

VINNUSAURUS
  • 1,518
  • 3
  • 18
  • 38
  • I think you should read here: https://developer.android.com/training/system-ui/immersive#EnableFullscreen and simply convert the Java code to C# counterpart – MatPag Nov 16 '18 at 12:16

1 Answers1

2

You need to declare it in your manifest file that your activity should be of full screen:

<activity android:name=".ActivityName"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>

And if you want to get it through code just use these lines in your activity's onCreate method:

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

Or Add the below line to the style.xml file

 //your theme
 <style name="Theme.AppCompat.Transparent.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
      //XML lines for full screen
      <item name="android:windowNoTitle">true</item>
      <item name="android:windowFullscreen">true</item>
 </style>

For more help take a look at this answer: Fullscreen Activity in Android?

VINNUSAURUS
  • 1,518
  • 3
  • 18
  • 38
Umair
  • 6,366
  • 15
  • 42
  • 50