Delphi 11.3 android透明窗体,[FMX] Android 下模拟模态窗口(半透明效果)

FMX的 Android 平台下没有模态窗口的概念,具体原因俺就不清楚,也不多说。这里的模拟只是一种视觉效果上的模拟,并不是真正的模态窗口。先看一下效果:

点击 ShowDialog 按钮时,显示上显示了一个半透明的窗口,将背景覆盖了,然后设置了一些内容,请用户操作。

Delphi 11.3 android透明窗体,[FMX] Android 下模拟模态窗口(半透明效果)_第1张图片

实际上要做的就是设置对话框窗口的几个属性:

Fill.Color :设置为 C8000000 ,我用的是黑色的半透明的效果

Fill.Kind :设置为 Solid,单色填充

Transparency :设置为 True,让背景透明

然后剩下的就是堆一堆控件,把对话框内容布局好就可以了。我上面的例子只是放了一个Panel,然后放了一个 Label 和两个 SpeedButton,在第一个窗体按钮的调用这个窗口Show出来就OK。

将代码简单的展示下:

Unit1.pas

Delphi/Pascal

unit Unit1;

interface

uses

System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,

FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls;

type

TForm1 = class(TForm)

Button1: TButton;

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

uses Unit2;

{$R *.fmx}

{$R *.LgXhdpiPh.fmx ANDROID}

procedure TForm1.Button1Click(Sender: TObject);

begin

Form2.Show;//我就自己写了这一行

end;

end.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

unitUnit1;

interface

uses

System.SysUtils,System.Types,System.UITypes,System.Classes,System.Variants,

FMX.Types,FMX.Controls,FMX.Forms,FMX.Graphics,FMX.Dialogs,FMX.StdCtrls;

type

TForm1=class(TForm)

Button1:TButton;

procedureButton1Click(Sender:TObject);

private

{Privatedeclarations}

public

{Publicdeclarations}

end;

var

Form1:TForm1;

implementation

usesUnit2;

{$R*.fmx}

{$R*.LgXhdpiPh.fmxANDROID}

procedureTForm1.Button1Click(Sender:TObject);

begin

Form2.Show;//我就自己写了这一行

end;

end.

Unit2.pas

Delphi/Pascal

unit Unit2;

interface

uses

System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,

FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls;

type

TForm2 = class(TForm)

Panel1: TPanel;

Label1: TLabel;

SpeedButton1: TSpeedButton;

SpeedButton2: TSpeedButton;

procedure SpeedButton2Click(Sender: TObject);

procedure SpeedButton1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form2: TForm2;

implementation

{$R *.fmx}

procedure TForm2.SpeedButton1Click(Sender: TObject);

begin

Close;//我这里写了一行代码,关闭

end;

procedure TForm2.SpeedButton2Click(Sender: TObject);

begin

Application.Terminate;//我这里写了两行代码退出程序

Close;

end;

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

unitUnit2;

interface

uses

System.SysUtils,System.Types,System.UITypes,System.Classes,System.Variants,

FMX.Types,FMX.Controls,FMX.Forms,FMX.Graphics,FMX.Dialogs,FMX.StdCtrls;

type

TForm2=class(TForm)

Panel1:TPanel;

Label1:TLabel;

SpeedButton1:TSpeedButton;

SpeedButton2:TSpeedButton;

procedureSpeedButton2Click(Sender:TObject);

procedureSpeedButton1Click(Sender:TObject);

private

{Privatedeclarations}

public

{Publicdeclarations}

end;

var

Form2:TForm2;

implementation

{$R*.fmx}

procedureTForm2.SpeedButton1Click(Sender:TObject);

begin

Close;//我这里写了一行代码,关闭

end;

procedureTForm2.SpeedButton2Click(Sender:TObject);

begin

Application.Terminate;//我这里写了两行代码退出程序

Close;

end;

完成整个效果,我写了四行代码,搞定。

你可能感兴趣的:(android)