
搜索框是TEDIT的後裔,並使用FireMonkey控件樣式。
將您的表單上TEDIT並打開其StyleLookup物業:

你可以看到,目前已經有不同stlyes。 所以我們想改變我們的SearchBox的StyleLookup。
由於SearchBox是ListView控件的私有成員(FSearchEdit),因此您無法直接訪問它。
您可以創建自己的ListView控件,它是TListView(TListViewBase)的後代或使用類助手。我選擇後者。
TListViewHelper = class helper for TListViewBase
private
function GetClearButton: Boolean;
procedure SetClearButton(const Value: Boolean);
public
property ShowSearchEditClearButton: Boolean read GetClearButton write SetClearButton;
end;
{ TListViewHelper }
function TListViewHelper.GetClearButton: Boolean;
begin
Result := Self.FSearchEdit.StyleLookup = ''; // default style
end;
procedure TListViewHelper.SetClearButton(const Value: Boolean);
begin
if Value then
Self.FSearchEdit.StyleLookup := '' // default style
else
Self.FSearchEdit.StyleLookup := 'editstyle';
end;
在FORMCREATE我們可以稱之爲ListView1.ShowSearchEditClearButton := False;
和清除按鈕不見了。

然而放大鏡圖標玻璃也消失了,因爲它不是我們設置爲StyleLookup
的editstyle
風格的一部分。
要取回圖標,我們必須創建自己的帶有放大鏡玻璃圖標但沒有清晰按鈕的樣式。
刪除一個TEDIT的形式,右鍵單擊它,然後選擇edit customized style
:

我們現在的範本:編輯和訪問控制佈局。
添加TActiveStyleObject到所有制結構,其重命名爲magnifierglass

更改TActiveStyleObject的ActiveLink
位圖。
在BitmapLinks-Editor中找到放大鏡玻璃圖標並選擇它(對於ActiveLink和SourceLink)。

現在文字將與圖標重疊。

要解決它,你對這些內容的左頁邊距(這是當前設置爲2px)更改爲類似20


您可以更高現在在樣式創建時以及窗體的樣式表中刪除窗體上的編輯。
打開樣式書並將新樣式的StyleName
重命名爲searcheditstylenoclearbtn
。

保存它,並在你的classhelper功能改變
Self.FSearchEdit.StyleLookup := 'editstyle';
到
Self.FSearchEdit.StyleLookup := 'searcheditstylenoclearbtn';
現在清除按鈕不見了。

如果你不想去通過創建自己的searcheditstylenoclearbtn您可以將下面的代碼保存爲searcheditstylenoclearbtn.style並在範本:編輯器加載的麻煩。

object TStyleContainer
object TLayout
StyleName = 'searcheditstylenoclearbtn'
Position.X = 530.000000000000000000
Position.Y = 399.000000000000000000
Size.Width = 100.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
Visible = False
TabOrder = 0
object TActiveStyleObject
StyleName = 'background'
Align = Contents
SourceLookup = 'Windows 10 Desktopstyle.png'
Size.Width = 100.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
ActiveTrigger = Focused
ActiveLink = <
item
CapInsets.Left = 7.000000000000000000
CapInsets.Top = 7.000000000000000000
CapInsets.Right = 7.000000000000000000
CapInsets.Bottom = 7.000000000000000000
SourceRect.Left = 266.000000000000000000
SourceRect.Top = 81.000000000000000000
SourceRect.Right = 305.000000000000000000
SourceRect.Bottom = 110.000000000000000000
end>
SourceLink = <
item
CapInsets.Left = 7.000000000000000000
CapInsets.Top = 7.000000000000000000
CapInsets.Right = 7.000000000000000000
CapInsets.Bottom = 7.000000000000000000
SourceRect.Left = 225.000000000000000000
SourceRect.Top = 81.000000000000000000
SourceRect.Right = 264.000000000000000000
SourceRect.Bottom = 110.000000000000000000
end>
TouchAnimation.Link = <>
end
object TLayout
StyleName = 'content'
Align = Client
Locked = True
Margins.Left = 20.000000000000000000
Margins.Top = 2.000000000000000000
Margins.Right = 2.000000000000000000
Margins.Bottom = 2.000000000000000000
Size.Width = 6.000000000000000000
Size.Height = 18.000000000000000000
Size.PlatformDefault = False
end
object TLayout
StyleName = 'buttons'
Align = Right
Locked = True
Margins.Top = 2.000000000000000000
Margins.Right = 2.000000000000000000
Margins.Bottom = 2.000000000000000000
Position.X = 48.000000000000000000
Position.Y = 2.000000000000000000
Size.Width = 50.000000000000000000
Size.Height = 18.000000000000000000
Size.PlatformDefault = False
end
object TBrushObject
StyleName = 'foreground'
Brush.Color = claBlack
end
object TBrushObject
StyleName = 'selection'
Brush.Color = x7F2A96FF
end
object TFontObject
StyleName = 'font'
end
object TLabel
StyleName = 'prompt'
Locked = True
Opacity = 0.500000000000000000
Visible = False
end
object TActiveStyleObject
StyleName = 'magnifierglass'
Align = Left
CapMode = Tile
Margins.Top = 1.000000000000000000
SourceLookup = 'Windows 10 Desktopstyle.png'
Position.Y = 1.000000000000000000
Size.Width = 20.000000000000000000
Size.Height = 21.000000000000000000
Size.PlatformDefault = False
WrapMode = Center
ActiveTrigger = Pressed
ActiveLink = <
item
SourceRect.Left = 4.000000000000000000
SourceRect.Top = 358.000000000000000000
SourceRect.Right = 20.000000000000000000
SourceRect.Bottom = 374.000000000000000000
end>
SourceLink = <
item
SourceRect.Left = 4.000000000000000000
SourceRect.Top = 358.000000000000000000
SourceRect.Right = 20.000000000000000000
SourceRect.Bottom = 374.000000000000000000
end>
TouchAnimation.Link = <>
end
end
end