修改Delphi 10.1.2 edit控件在android的复制、剪切和粘贴样式

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;

 

https://www.cnblogs.com/qiufeng2014/p/6574701.html

相关文章

 从网上看到《Delphi API HOOK完全说明》这篇文章,基本上都...
  从网上看到《Delphi API HOOK完全说明》这篇文章,基本上...
ffmpeg 是一套强大的开源的多媒体库 一般都是用 c/c+&#x...
32位CPU所含有的寄存器有:4个数据寄存器(EAX、EBX、ECX和ED...
1 mov dst, src dst是目的操作数,src是源操作数,指令实现的...