修改Delphi 10.1.2 edit控制項在android的複製、剪下和粘貼樣式

來源:互聯網
上載者:User

標籤:man   tsp   tty   orm   begin   nts   window   image   alt   

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;

修改Delphi 10.1.2 edit控制項在android的複製、剪下和粘貼樣式

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.