Modify the copy, cut, and paste styles of the Delphi 10.1.2 Edit control on Android

Source: Internet
Author: User

Delphi 10.1.2 Edit Control in the Android default copy, cut and paste style is too ugly, enlightened can-delphiteacher hints, with the simplest code modified slightly changed.

Default Style:

Modified style:

Modify FMX.Platform.Android.pas

Locate procedure Twindowmanager.showcontextmenu (const itemstoshow:tcontextmenuitems) and add the copy, Cut, and paste buttons to the following scarlet letter The SetBackgroundColor property .

Fcopybutton.setbackgroundcolor (Talphacolors.yellowgreen);//------Add this line, you can modify it according to your preference
Fcutbutton.setbackgroundcolor (Talphacolors.yellowgreen);//------Add this line, you can modify it according to your preference
Fpastebutton.setbackgroundcolor (Talphacolors.yellowgreen);//------Add this line, you can modify it according to your preference

Procedure Twindowmanager.showcontextmenu (const itemstoshow:tcontextmenuitems);
Var
La:ttextlayout;
P:tpoint;
Hasselection, Hasclipboard:boolean;
Approxwidth:integer;
Approxheight:integer;
Clipboardvalue:tvalue;
Resid:integer;
Textinput:itextinput;
Virtualkeyboard:ivirtualkeyboardcontrol;
Clipboardsvc:ifmxclipboardservice;
Begin
Destroypastemenutimer;
Approxwidth: = fcontextmenupopupsize.cx;
Approxheight: = fcontextmenupopupsize.cy;
If not fcontextmenuvisible and Supports (Ffocusedcontrol, Itextinput, TextInput) and not fselectioninprogress then
Begin
Fcontextmenuvisible: = True;
Hasselection: = Not TextInput.GetSelection.IsEmpty;
TPlatformServices.Current.SupportsPlatformService (Ifmxclipboardservice, clipboardsvc);
Clipboardvalue: = Clipboardsvc.getclipboard;
Hasclipboard: = Not clipboardvalue.isempty and not ClipboardValue.ToString.IsEmpty;
If Fcontextmenupopup = Nil Then
Begin
Fcontextmenulayout: = TJLinearLayout.JavaClass.init (tandroidhelper.activity);
Fcontextbuttonslayout: = TJLinearLayout.JavaClass.init (tandroidhelper.activity);

LA: = TTextLayoutManager.DefaultTextLayout.Create;
KAI Font.style: = LA. Font.style + [Tfontstyle.fsbold];

P: = Point (0, 0);
Supports (Ffocusedcontrol, Ivirtualkeyboardcontrol, VirtualKeyboard);

If Hasselection Then
Begin
Copy button
if (tcontextmenuitem.copy in Itemstoshow) and ((VirtualKeyboard = nil) or not virtualkeyboard.ispassword) then
Begin
ResID: = Tandroidhelper.getresourceid (' android:string/copy ');
If ResID <> 0 Then
KAI Text: = tandroidhelper.getresourcestring (ResID)
Else
KAI Text: = Seditcopy.toupper;
Fcopybutton: = TJButton.JavaClass.init (tandroidhelper.activity);
If ResID <> 0 Then
Fcopybutton.settext (ResID)
Else
Fcopybutton.settext (Strtojcharsequence (LA. Text));
Fcopybutton.settypeface (TJTypeface.JavaClass.DEFAULT_BOLD);
Fcopybutton.setbackgroundcolor (Talphacolors.yellowgreen);//------Add this line, you can modify it according to your preference
Fcopyclicklistener: = tcopybuttonclicklistener.create;
Fcopybutton.setonclicklistener (Fcopyclicklistener);
LA. Font.Size: = fcopybutton.gettextsize;
p.x: = p.x + ceil ((LA. TextWidth + 2) * Fscale);
P.Y: = Max (P.y, Ceil (LA. TextHeight + 2) * Fscale));
Approxheight: = p.y + Fcopybutton.getpaddingtop + fcopybutton.getpaddingbottom;
End
Cut button
if (Tcontextmenuitem.cut in Itemstoshow) and is Textreadonly and ((VirtualKeyboard = nil) or not virtualkeyboard.ispasswo RD) Then
Begin
ResID: = Tandroidhelper.getresourceid (' android:string/cut ');
If ResID <> 0 Then
KAI Text: = tandroidhelper.getresourcestring (ResID)
Else
KAI Text: = Seditcut.toupper;
Fcutbutton: = TJButton.JavaClass.init (tandroidhelper.activity);
If ResID <> 0 Then
Fcutbutton.settext (ResID)
Else
Fcutbutton.settext (Strtojcharsequence (LA. Text));
Fcutbutton.settypeface (TJTypeface.JavaClass.DEFAULT_BOLD);
Fcutbutton.setbackgroundcolor (Talphacolors.yellowgreen);//------Add this line, you can modify it according to your preference
Fcutclicklistener: = tcutbuttonclicklistener.create;
Fcutbutton.setonclicklistener (Fcutclicklistener);
KAI Font.Size: = fcopybutton.gettextsize;
p.x: = p.x + ceil ((LA. TextWidth + 2) * Fscale);
P.Y: = Max (P.y, Ceil (LA. TextHeight + 2) * Fscale));
End
End

If Hasclipboard and (Tcontextmenuitem.paste in Itemstoshow) and is textreadonly then
Begin
Paste button
ResID: = Tandroidhelper.getresourceid (' Android:string/paste ');
If ResID <> 0 Then
KAI Text: = tandroidhelper.getresourcestring (ResID)
Else
KAI Text: = Seditpaste.toupper;
Fpastebutton: = TJButton.JavaClass.init (tandroidhelper.activity);
If ResID <> 0 Then
Fpastebutton.settext (ResID)
Else
Fpastebutton.settext (Strtojcharsequence (LA. Text));
Fpastebutton.settypeface (TJTypeface.JavaClass.DEFAULT_BOLD);
Fpastebutton.setbackgroundcolor (Talphacolors.yellowgreen);//------Add this line, you can modify it according to your preference
Fpasteclicklistener: = tpastebuttonclicklistener.create;
Fpastebutton.setonclicklistener (Fpasteclicklistener);
LA. Font.Size: = fpastebutton.gettextsize;
p.x: = p.x + ceil ((LA. TextWidth + 2) * Fscale);
P.Y: = Max (P.y, Ceil (LA. TextHeight + 2) * Fscale));
If Approxheight = 0 Then
Approxheight: = p.y + Fpastebutton.getpaddingtop + fpastebutton.getpaddingbottom;
End

Modify the copy, cut, and paste styles of the Delphi 10.1.2 Edit control on Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.