Mobile App Dev Diary

Android (Java, Kotlin), iOS (Swift), Xamarin (C#)

Xamarin.Forms / Prevent iOS statusbar is overwrapped

To avoid iOS statusbar is hidden by UI components, use this.

<?xml version="1.0" encoding="utf-8"?>
<ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:calc"
    x:Class="calc.calcPage">

    <!-- for iOS -->
    <!-- prevent statusbar is overwrapped -->
    <ContentPage.Padding>
        <OnPlatform x:TypeArguments="Thickness" iOS="0, 20, 0, 0" />
    </ContentPage.Padding>

</ContentPage>

Kotlin 1.1 / Screen transition with Intent

Screen transition in Kotlin version 1.1.

When you transite to “NextActivity”, use this.

val intent = Intent(applicationContext, NextActivity::class.java)
startActivity(intent)

Or you may want to define package-level function to instantiate Intent. Simply speaking, “package-level” means outside class definition.

//package-level functiono
fun getNextActivityIntent(context: Context) : Intent {
    return Intent(context, NextActivity::class.java)
}

You can call this function from Activity class.

startActivity(getDetailActivityIntent(applicationContext))