Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Set bgcolor of selected TTabItem on TTabControl


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 6 - Last Post: May 4, 2016 11:12 AM Last Post By: Chris Dunn
David Keith

Posts: 196
Registered: 12/10/99
Set bgcolor of selected TTabItem on TTabControl  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 2, 2016 8:22 AM
Android/iOS -

Need to set the background color of the selected tab ***IN CODE***,
not in the fubar'ed stylemonkey nonsense.

Anyone know how to do this? Is it even possible?

Tried this:

http://stackoverflow.com/questions/35916600/how-can-i-change-the-background-color-of-ttabitem-of-ttabcontrol-in-firemonkey/35917561#35917561

Didn't work.

Tried this:
procedure TForm1.TabControl1Change(Sender: TObject);
var
  i,n: Integer;
  BckObject: TFMXObject;
  rct: TRectangle;
  ATab: TTabItem;
begin
  for i := 0 to Pred(TabControl1.TabCount) do
  begin
    ATab := TabControl1.Tabs[i];
    BckObject := ATab.FindStyleResource('background');
    if Assigned(BckObject) and (BckObject is TSubImage) then
    begin
      for n := 0 to Pred(ATab.ControlsCount) do
        if ATab.Controls[i].InheritsFrom(TRectangle) or (ATab.Controls[i] is TRectangle) then
          if ATab = TabControl1.ActiveTab then
            TRectangle(ATab.Controls[i]).Fill.Color := TColorLabel.TColorToTAlphaColor($336699)
          else
            TRectangle(ATab.Controls[i]).Fill.Color := TAlphaColorRec.White;
    end;
  end;
end;


Doesn't work.

Thanks.
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: Set bgcolor of selected TTabItem on TTabControl [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 2, 2016 12:57 PM   in response to: David Keith in response to: David Keith
Hello,

it is possible, if the TTabItem has some rectangle which can be filled
with some color. If not you need to create a new style for it via form
designer where you add a TRectangle as intermediate object.

Ensure that HitTest is off, otherwise the TTabItem cannot be clicked
anymore.

At runtime there's some call (don't ask me I don't know it off head) you
can use to get the reference to that TRectangle and then you can change
it's fill color.

Greetings

Markus
Chris Dunn

Posts: 160
Registered: 8/22/11
Re: Set bgcolor of selected TTabItem on TTabControl  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 3, 2016 9:14 AM   in response to: David Keith in response to: David Keith
Right click the object and select edit default style (in your case TTabItem)
you can see the objects that make up the item in the designer to manipulate them at run time.
Make sure to delete the style book that automatically gets created after leaving the designer.

This code will change the color to green on android.

procedure TSomeForm.ATabItemApplyStyleLookup(Sender: TObject);
var Obj: TFmxObject;
Rectangle1: TRectangle;
begin
Obj := ATabItem.FindStyleResource('bottom');
if Obj <> nil then
begin
TControl(Obj).Margins := TBounds.Create(TRectF.Create(-2, -2, -2, -2));
Rectangle1 := TRectangle.Create(Obj);
Obj.AddObject(Rectangle1);
Rectangle1.Align := TAlignLayout.Client;
Rectangle1.Fill.Color := TAlphaColorRec.Green;
Rectangle1.Stroke.Color := TAlphaColorRec.Null;
Rectangle1.HitTest := False;
Rectangle1.SendToBack;
end;
end;
David Keith

Posts: 196
Registered: 12/10/99
Re: Set bgcolor of selected TTabItem on TTabControl  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 3, 2016 9:38 AM   in response to: Chris Dunn in response to: Chris Dunn
On 5/3/2016 12:14, Chris Dunn wrote:
Right click the object and select edit default style (in your case TTabItem)
you can see the objects that make up the item in the designer to manipulate them at run time.
Make sure to delete the style book that automatically gets created after leaving the designer.

This code will change the color to green on android.

procedure TSomeForm.ATabItemApplyStyleLookup(Sender: TObject);
var Obj: TFmxObject;
Rectangle1: TRectangle;
begin
Obj := ATabItem.FindStyleResource('bottom');
if Obj <> nil then
begin
TControl(Obj).Margins := TBounds.Create(TRectF.Create(-2, -2, -2, -2));
Rectangle1 := TRectangle.Create(Obj);
Obj.AddObject(Rectangle1);
Rectangle1.Align := TAlignLayout.Client;
Rectangle1.Fill.Color := TAlphaColorRec.Green;
Rectangle1.Stroke.Color := TAlphaColorRec.Null;
Rectangle1.HitTest := False;
Rectangle1.SendToBack;
end;
end;
Thank you. I will try your code. I don't get the 'Edit Default Style'
menu either from the structure window or from the control itself.
Chris Dunn

Posts: 160
Registered: 8/22/11
Re: Set bgcolor of selected TTabItem on TTabControl  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 3, 2016 9:43 AM   in response to: David Keith in response to: David Keith
Im using rad studio 10 and 10.1 not sure about the others.
[http://docwiki.embarcadero.com/RADStudio/Seattle/en/Customizing_FireMonkey_Applications_with_Styles]

older versions you need to extract the default style and load it into a style book that you can read
[https://delphihaven.wordpress.com/2013/12/31/inspecting-platform-styles-redux/]

Edited by: Chris Dunn on May 3, 2016 11:09 AM
David Keith

Posts: 196
Registered: 12/10/99
Re: Set bgcolor of selected TTabItem on TTabControl [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 4, 2016 9:29 AM   in response to: Chris Dunn in response to: Chris Dunn
On 5/3/2016 14:10, Chris Dunn wrote:
Im using rad studio 10 and 10.1 not sure about the others.
[http://docwiki.embarcadero.com/RADStudio/Seattle/en/Customizing_FireMonkey_Applications_with_Styles]

older versions you need to extract the default style and load it into a style book that you can read
[https://delphihaven.wordpress.com/2013/12/31/inspecting-platform-styles-redux/]

Edited by: Chris Dunn on May 3, 2016 11:09 AM

I'm using 10 Enterprise and I don't get the menu options anywhere, not
even if I drop a tstylebook on the frame.
Chris Dunn

Posts: 160
Registered: 8/22/11
Re: Set bgcolor of selected TTabItem on TTabControl [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 4, 2016 11:12 AM   in response to: David Keith in response to: David Keith
yep im on enterprise as well. maybe try reinstalling. sounds mangled.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02