Documente Academic
Documente Profesional
Documente Cultură
Contents
[hide]
Note: This page describes how to develop multi-device applications that target the Android platform.
See Android Mobile Application Development for topics that are not specific to the development
phase, such as configuring your PC and Android devices to work with RAD Studio.
Style Selector
The style selector's drop-down menu lists all the styles that you can apply to the Master view.
Select the Android style from the style selector to see all the properties on the components according to the
target platform.
View Selector
At the top of the multi-device Form Designer is the view selector:
The view selector's drop-down menu lists all the available views, which show the different platforms, such
as iOS, Android, Windows and OS X.
Use the Master form for a general design of your application. Then you can add new views to your project
in order to customize your application for a specific device type. You can even create new customized
views; see Adding a Customized View to the View Selector. The predefined Android device views are:
Note: For more information about the resolution of the predefined views see Display Specifications.
Note: Select the Android target platform to see all the available components for Android, otherwise
they appear grayed out.
Add new views to your project in order to customize your application for a specific Android device type. All
the views inherit the components and properties from the Master form. For more information see Form
Designer.
Note: If you want to customize some aspects of your application for all Android devices you can do
it using the Master form, provided you do not want to propagate to the rest of platforms. Otherwise
use the Code Editor, for example:
// You will see the changes applied at run-time.
{$IFDEF ANDROID}
SpeedButton1.StyleLookup := priortoolbutton;
{$ENDIF}
• Mobile Tutorial: Using Layout to Adjust Different Form Sizes or Orientations (iOS and Android)
(shows how to use the Master form for different form factors (such as phone or tablet), without
using different views for each form factor)
The FireMonkey framework is ideal for the Android target platform, and it supports other target platforms
as well.
RTL
Some run-time library (RTL) units that provide basic functionality are common for every supported target
platform (including Android), such as System.pas or System.SysUtils.pas.
A number of RTL units are Android-only (see Android API and Java Libraries). These units are prefixed
with the Androidapi unit scope.
The RTL contains a number of units that provide Delphi and C++ interfaces to the Android native API.
These units are scoped with Androidapi and are typically located in the source\rtl\android\ directory of
your RAD Studio installation. The FireMonkey framework relies on some of these units. You may also use
them directly if you want.
You can also use parts of the Android API that are not mapped by the RTL, or use your own Java libraries in
your project:
For example, you cannot use any of the following as project names:
And so forth.
• Set the Align property for all controls that are children of a TToolbar. For example, the following
are Align property values:
For example, assume you have a toolbar with a child TLabel as the Title, and two left-aligned
speedbuttons with space between each button:
▪ Margins Left = 5
• To format a segmented control (styled TSpeedButtons with a shared group name) so that it is
centered on the toolbar:
1. Add a TLayout control to the TToolBar.
2. Set TLayout.Align to Center.
3. Add buttons to the TLayout and set alignment properties and margins for each button (that is,
Align = Left, Margins = Left, Margins = Right, and so forth).
▪ For an example, see Mobile Tutorial: Using a Button Component with Different
Styles (iOS and Android).
• To use TLabel, you must set TLabel.AutoSize = False and set the Align property.
o To center the label on a toolbar that already has buttons, you must set TLabel.Align =
Contents and select Send to Back on the context menu.
Similar alignment rules pertain to other controls. For example, assume you have added a TSwitch to a
ListBox item; to have the switch aligned to the right and centered vertically, set the following properties for
TSwitch:
• Align= Right
• Margins Right = 5
However, if you deploy the app at this point to a target device, the fonts in the app are rendered using only
the installed fonts available on the device. You need to add the font to your project using the Deployment
Manager to ensure that the fonts you see at design time in the IDE are copied over to the device.
Here are the basic steps for incorporating a custom font in your Android app::
Full instructions and downloadable files for creating a mobile project that uses a custom installed font (Font
Awesome) are available here:
• http://community.embarcadero.com/index.php/blogs/entry/true-type-font-iconography-for-android-
and-ios-apps
To know whether a font might be available at run time on a specific mobile device, you need to check
whether the font you are using at design time is supported on your target devices:
For example:
• To use the Android device's camera, ensure that the following permissions are enabled:
o Camera
o Read/Write external storage
• To use GPS location on the Android device, ensure that one or more of the Location Access
permissions are enabled:
o Access coarse location
o Access fine location
o Access location extra commands
• To record audio on the Android device, ensure that the following permission is enabled:
o Record audio
Delphi:
C++:
if (Key == vkHardwareBack) {
// Do whatever you want here
Key = 0; // Set Key = 0 if you want to prevent the default action
}
Tip: The Tabbed with Navigation mobile template implements this event handling.
Making Your Application Run in Fullscreen Mode
By default, Android applications display the Android status bar/title bar.
If you want your application to run in fullscreen mode and hide the Android status/title bar, select Project >
Options > Version Info and change the value of the theme key to No TitleBar.
To enable the user to hide the virtual keyboard by clicking the Return key, set KillFocusByReturn = True.
Multiple resolutions can be supported by creating a MultiResBitmap using the MultiResBitmap Editor. For
more information, see Using Multi-Resolution Bitmaps.
Delphi:
TPath.Combine(TPath.GetDocumentsPath, 'filename') { Internal }
TPath.Combine(TPath.GetSharedDocumentsPath, 'filename') { External }
C++:
System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetDocumentsPath(),
L"filename") // Internal
System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetSharedDocumentsPath(),
L"filename") // External
Here filename is the name of your file, such as 'dbdemos.gdb' in the screenshot above. The TPath record is
declared in System.IOUtils unit, so you need to add System.IOUtils in the uses clause.
Find documentation about other, platform-agnostic features in the FireMonkey Applications Guide.
Adding Views to Your Multi-Device Project
Go Up to Using FireMonkey Views
A view is a version of the Master view that is customized for a given device or a type of device, for example
Windows Desktop.
• To toggle between views in the Form Designer, select a view on the drop-down Views menu.
• To add one or more views to your multi-device project, click a platform in the Available list. The
view you added is immediately used for your project in the Form Designer, and the view's name
appears under a new group, Created, separated from the Available views:
When you add a view, a new form is included in the project and is saved in the project folder with the
following name structure:
<Unit_name><platform>
Delphi:
The names of new view forms are listed in the Implementation section:
implementation
{$R *.fmx}
{$R *.Windows.fmx MSWINDOWS}
{$R *.iPhone4in.fmx IOS}
{$R *.LgXhdpiPh.fmx ANDROID}
C++:
The names of new view forms are listed in the <Unit_name>.cpp:
To learn how to add customized views that are not listed in the Available section, see Adding a Customized
View to the View Selector.