Create layout
This section describes how to create the app layout.
Create the buttons and Textview
This app contains 6 buttons.
- toggleAdminBtn — Prompts the user to activate/deactivate device administrator for the app.
- activateLicenseBtn — Activates the Knox ELM license key.
- deactivateLicenseBtn — Grants runtime permission to create a shortcut to the Kiosk app.
- activateBackwardsCompatibleKeyBtn — Activates the Knox backwards compatibility license key.
- toggleDefaultKioskBtn — Activates/deactivates default Kiosk mode.
- toggleCustomKioskBtn — Activates/deactivates custom Kiosk mode.
Open activity_main.xml and insert the following XML mark up to create your screen layout.
To resolve the @string
errors, copy the 2 files below from the sample app into your project.
- background.xml — KnoxSdkSample\app\src\main\res\drawable\Background
- strings.xml — KnoxSdkSample\app\src\main\res\values\strings
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainpage"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.samsung.knox.example.kioskmode.MainActivity">
<TextView
android:id="@+id/logview_id"
android:gravity="bottom"
android:layout_width="320dp"
android:layout_height="230dp"
android:textColor="#3F51B5"
android:background="@drawable/background"
android:scrollbars="vertical"
android:paddingLeft="10dp"
android:layout_marginTop="22dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ScrollView
android:id="@+id/scrollView"
android:layout_marginTop="10dp"
android:layout_below="@id/logview_id"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/toggleAdminBtn"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/activate_admin" />
<Button
android:id="@+id/activateLicenseBtn"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/toggleAdminBtn"
android:layout_below="@+id/toggleAdminBtn"
android:text="@string/activate_license" />
<Button
android:id="@+id/deactivateLicenseBtn"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@id/activateLicenseBtn"
android:layout_centerHorizontal="true"
android:text="Deactivate license" />
<Button
android:id="@+id/activateBackwardsCompatibleKeyBtn"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@+id/deactivateLicenseBtn"
android:layout_centerHorizontal="true"
android:text="Activate backwards compatible key"
android:visibility="gone" />
<Button
android:id="@+id/toggleDefaultKioskBtn"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignStart="@id/toggleAdminBtn"
android:layout_below="@id/activateBackwardsCompatibleKeyBtn"
android:text="@string/toggle_kiosk" />
<Button
android:id="@+id/toggleCustomKioskBtn"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@id/toggleDefaultKioskBtn"
android:layout_alignStart="@id/toggleAdminBtn"
android:text="@string/toggle_kiosk_settings" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
The button that activates the backwards compatibility key only appears if the device’s Knox version between is between 2.5 and 2.7.1, or Knox API 17 to 21. Depending on your Knox version, you should now see 5 or 6 buttons in the middle of the screen.
- ACTIVATE ADMIN
- ACTIVATE LICENSE
- DEACTIVATE LICENSE
- ACTIVATE BACKWARDS COMPATIBLE KEY
- TOGGLE DEFAULT KIOSK
- TOGGLE CUSTOM KIOSK You will later assign methods to these buttons to control their respective actions. There is also a TextView at the top of the screen that displays log messages.
Create the custom Kiosk mode settings layout
Next, create checkboxes to enable or disable different device policies when Kiosk mode is enabled.
Under the res
folder, open the subfolder layout in Android view, then create a new Layout resource file with the name prompt_kiosk_setting.xml.
Open the newly created prompt_kiosk_setting.xml file and insert the following XML markup to create your custom Kiosk mode layout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="20dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:paddingBottom="10dp"
android:id="@+id/kiosk_config_group"
android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView
android:id="@+id/dtxtKioskSetting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/kiosk_setting"
android:textColor="@android:color/black" />
<CheckBox
android:id="@+id/chkSettingsChange"
android:layout_below="@id/dtxtKioskSetting"
android:text="@string/allow_settings_changes"
android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/chkAllowStatusBar"
android:layout_below="@id/chkSettingsChange"
android:text="@string/allow_status_bar"
android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/chkStatusBarExpansion"
android:layout_below="@id/chkAllowStatusBar"
android:checked="true"
android:text="@string/allow_status_bar_expansion"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/chkAllowSystemBar"
android:layout_below="@id/chkStatusBarExpansion"
android:text="@string/allow_system_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/chkAllowTaskManager"
android:layout_below="@id/chkAllowSystemBar"
android:text="@string/allow_task_manager"
android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/chkAllowHomekey"
android:layout_below="@id/chkAllowTaskManager"
android:text="@string/allow_home_key"
android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/chkAllowAirCommand"
android:layout_below="@id/chkAllowHomekey"
android:text="@string/allow_air_command"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/chkAllowAirview"
android:layout_below="@id/chkAllowAirCommand"
android:text="@string/allow_air_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/chkAllowMultiwindow"
android:layout_below="@id/chkAllowAirview"
android:text="@string/allow_multiwindow"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/chkAllowSmartClip"
android:layout_below="@id/chkAllowMultiwindow"
android:text="@string/allow_smart_clip"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/chkAllowNavBar"
android:layout_below="@id/chkAllowSmartClip"
android:text="@string/allow_nav_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/chkWipeRecentTasks"
android:layout_below="@id/chkAllowNavBar"
android:text="@string/wipe_recent_tasks"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/chkClearNotifications"
android:layout_below="@id/chkWipeRecentTasks"
android:text="@string/clear_notifications"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
You should now see the following checkboxes on the screen, with some settings already enabled.
To change which checkboxes are selected by default, in the XML markup, add or remove the following line under each setting: android:checked="true"
.
Create the Exit Custom Kiosk Mode Settings layout
Now, create a confirmation prompt that appears when exiting custom Kiosk mode.
Under the res
folder, open the subfolder layout in Android view, then create a new Layout resource file with the name exit_custom_kiosk.xml.
Open the newly created exit_custom_kiosk.xml file and insert the following XML markup to create your custom Kiosk mode layout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="20dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:paddingBottom="10dp"
android:id="@+id/kiosk_config_group"
android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView
android:id="@+id/dtxtKioskSetting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/exit_kiosk"
android:textColor="@android:color/black" />
</RelativeLayout>
You should see the following confirmation prompt on the device’s screen:
For information on creating Android layouts, see Create your first Android app.
Tutorial progress
You’ve completed 1 of 7 steps!
NextOn this page
Is this page helpful?