Bonjour,
je dois dire que je ne pratique pas le FMX 
mais je me suis quand même pris au jeu 
et j'ai trouvé une solution qui semble fonctionner avec tous les styles disponibles de base avec 10.2
je récupère la couleur par défaut après un changement de style et l'applique au TText
j'ai tenu compte du problème de départ à savoir le changement de couleur du texte rouge/vert/défaut
je ne sais pas si ça va convenir vu mon niveau en FMX 
mais bon je me lance 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
| var
frm_DefColorMain: Tfrm_DefColorMain;
implementation
{$R *.fmx}
uses System.UIConsts , crFilesUtils;
const
STYLE_PATH = 'C:\Users\Public\Documents\Embarcadero\Studio\19.0\Styles\';
type
// vue qu'on détourne 'TFontColorForState' de l'utilisation normal
// j'ai redéfini un type 'TFontColorIndex' pour différencier
// et raccourcir un peu le code ^^
TFontColorIndex = record
const
Default = TFontColorForState.TIndex.Normal;
Error = TFontColorForState.TIndex.Hot;
Ok = TFontColorForState.TIndex.Pressed;
end;
procedure Tfrm_DefColorMain.btn_ApplyClick(Sender: TObject);
begin
if ListBox1.ItemIndex <> -1 then
begin
if StyleBook1.UseStyleManager then
StyleBook1.FileName := STYLE_PATH + ListBox1.Items[ListBox1.ItemIndex]
else
StyleBook1.LoadFromFile(STYLE_PATH + ListBox1.Items[ListBox1.ItemIndex]);
TStyleManager.SetStyle(StyleBook1.Style);
Label2.Text := ListBox1.Items[ListBox1.ItemIndex];
end;
end;
// c'est ici que je récupère la couleur par défaut du TLabel
procedure Tfrm_DefColorMain.Label1ApplyStyleLookup(Sender: TObject);
var
aTextObject: TText;
begin
if Sender is TLabel then
if TLabel(Sender).FindStyleResource<TText>('text', aTextObject) then
begin
// on prend toutes les caractéristiques en une fois
txt_Status.TextSettings.Assign(aTextObject.TextSettings);
with txt_Status.TextSettings do
begin
// au passage on peut changer la font du TLabel
//aTextObject.Font.Family := 'Comic Sans MS';
// ou que celle qui nous interesse
//FontColor := aTextObject.TextSettings.FontColor;
// et on se sert de 'FontColorForState' (non utilisé pour un TText) pour stocker
// les couleurs qui nous interesse
FontColorForState.Color[TFontColorIndex.Default] := FontColor;
FontColorForState.Color[TFontColorIndex.Error] := TAlphaColors.Red;
FontColorForState.Color[TFontColorIndex.Ok] := TAlphaColors.Green;
end;
end;
RadioButton1Change(nil);
Label2.Text := ExtractFileName(StyleBook1.FileName);
end;
procedure Tfrm_DefColorMain.ListBox1DblClick(Sender: TObject);
begin
if ListBox1.ItemIndex <> -1 then
begin
if StyleBook1.UseStyleManager then
StyleBook1.FileName := STYLE_PATH + ListBox1.Items[ListBox1.ItemIndex]
else
StyleBook1.LoadFromFile(STYLE_PATH + ListBox1.Items[ListBox1.ItemIndex]);
TStyleManager.SetStyle(StyleBook1.Style);
end;
end;
procedure Tfrm_DefColorMain.RadioButton1Change(Sender: TObject);
var
I: Integer;
aComp: TRadioButton;
begin
if not (Sender is TRadioButton) then
for I := 1 to 3 do
begin
aComp := TRadioButton(FindComponent('RadioButton'+I.ToString));
if aComp.IsChecked then
begin
Sender := aComp;
Break
end;
end;
// simulation d'un message avec couleur en fonction de l'importance
if TRadioButton(Sender).IsChecked then
case TRadioButton(Sender).Tag of
0: begin
txt_Status.Text := 'Un message en couleur par défaut';
with txt_Status.TextSettings do
FontColor := FontColorForState.CurrentColor[TFontColorIndex.Default];
end;
1: begin
txt_Status.Text := 'Un message d''erreur en Rouge';
with txt_Status.TextSettings do
FontColor := FontColorForState.CurrentColor[TFontColorIndex.Error];
end;
2: begin
txt_Status.Text := 'Un message de réussite en Vert';
with txt_Status.TextSettings do
FontColor := FontColorForState.CurrentColor[TFontColorIndex.Ok];
end;
end;
end;
procedure Tfrm_DefColorMain.btn_UpdateFlagClick(Sender: TObject);
var ai : TFMXObject;
begin
// en cas de changement de Style
// on vérifie la présence de 'DrapeauRectangle'
if Assigned(StyleBook1.CurrentItem.Style.FindStyleResource('DrapeauRectangle')) then
begin
if RoundRect1.Tag = 0 then
begin
ai := StyleBook1.CurrentItem.Style.FindStyleResource('be');
RoundRect1.Tag := 1;
end
else
begin
RoundRect1.Tag := 0;
ai := StyleBook1.CurrentItem.Style.FindStyleResource('fr_fra');
end;
RoundRect1.Fill.Gradient := TBrushObject(ai).Brush.Gradient;
end;
end;
procedure Tfrm_DefColorMain.FormCreate(Sender: TObject);
begin
{procedure FindFiles(Directory: string; FilesMask: string; aList: TStrings; const
SubFolders: Boolean = True; const FullPath: Boolean = True);}
// FindFiles et une simple procédure qui retourne une liste (TStrings)
// de noms de fichiers correspondant au chemin de recherche (STYLE_PATH)
// et au mask de recherche '*.style'
crFilesUtils.FindFiles(STYLE_PATH, '*.style', ListBox1.Items, False, False);
RadioButton1.Tag := Ord(TFontColorIndex.Default);
RadioButton2.Tag := Ord(TFontColorIndex.Error);
RadioButton3.Tag := Ord(TFontColorIndex.Ok);
RoundRect1.Fill.Kind := TBrushKind.Gradient;
end;
end. |
si tu as besoin de plus, les sources aux complet ou autre, n'hésites pas 
Cordialement,
@+
ps: ah oui ... j'ai réussi, non sans mal, à intégrer les deux styles pour les drapeaux
donc: où les as-tu placés dans le Style ?
et aussi ceci pour qu'enfin le résultat soit bon:
RoundRect1.Fill.Kind := TBrushKind.Gradient;
Partager