Android实例-利用WebBrowser实现浏览器(XE8+小米2)

时间:2023-03-08 20:08:42

Android实例-利用WebBrowser实现浏览器(XE8+小米2)

结果:

1.网络好的情况下,打开很快,很流畅。

2.地址栏真心不好使,如果真要做应用,这块必须自己优化一下。

实例代码:

 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,
FMX.Edit, FMX.Controls.Presentation, FMX.WebBrowser; type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
ToolBar1: TToolBar;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
StatusBar1: TStatusBar;
procedure Button1Click(Sender: TObject);
procedure Edit1KeyDown(Sender: TObject; var Key: Word; var KeyChar: Char;
Shift: TShiftState);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.fmx}
{$R *.NmXhdpiPh.fmx ANDROID} //打开网页
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.URL := Edit1.Text;
end; //返回
procedure TForm1.Button2Click(Sender: TObject);
begin
WebBrowser1.GoBack;
end; //前进
procedure TForm1.Button3Click(Sender: TObject);
begin
WebBrowser1.GoForward;
end; procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; var KeyChar: Char;
Shift: TShiftState);
begin
if Key = vkReturn then
begin
//当按下按钮时,隐藏输入键盘并把焦点移动到 btnGO 上。
WebBrowser1.URL := edit1.Text;
Button1.SetFocus;
end;
end; end.