Delphi 10.1.2 edit控件在android默认的复制、剪切和粘贴样式太丑,经悟能-DelphiTeacher的提示,用最简单的代码修改后稍有改观。
默认的样式:
修改后的样式:
修改FMX.Platform.Android.pas
找到procedure TWindowManager.ShowContextMenu(const ItemsToShow: TContextMenuItems),按下面的红字增加Copy、cut和Paste button的setBackgroundColor属性。
FCopyButton.setBackgroundColor(TAlphaColors.Yellowgreen);//------增加这行,可以根据自己的喜好修改
FCutButton.setBackgroundColor(TAlphaColors.Yellowgreen);//------增加这行,可以根据自己的喜好修改
FPasteButton.setBackgroundColor(TAlphaColors.Yellowgreen);//------增加这行,可以根据自己的喜好修改
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;
LA.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
LA.Text := TAndroidHelper.GetResourceString(ResID)
else
LA.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);//------增加这行,可以根据自己的喜好修改
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 not TextReadOnly and ((VirtualKeyboard = nil) or not VirtualKeyboard.IsPassword) then
begin
ResID := TAndroidHelper.GetResourceID('android:string/cut');
if ResID <> 0 then
LA.Text := TAndroidHelper.GetResourceString(ResID)
else
LA.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);//------增加这行,可以根据自己的喜好修改
FCutClickListener := TCutButtonClickListener.Create;
FCutButton.setOnClickListener(FCutClickListener);
LA.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 not TextReadOnly then
begin
//Paste button
ResID := TAndroidHelper.GetResourceID('android:string/paste');
if ResID <> 0 then
LA.Text := TAndroidHelper.GetResourceString(ResID)
else
LA.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);//------增加这行,可以根据自己的喜好修改
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;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
2015-03-18 Arduino Nano 读取ADS1100实例