如何防止 MultiView 不透明度影响 Delphi 中的子组件文本?

How to prevent MultiView opacity from affecting children components texts in Delphi?

我在 Firemonkey 中使用 MultiView 和一些 TButton 按钮。 multiView 在 0.5 时不透明,这会导致按钮也不透明。

问题:有没有办法防止 MultiView 不透明度影响按钮文本?也就是说,按钮的文本将继续使用明亮的颜色,但按钮的 "body" 将是不透明的。我见过一些具有此视觉功能的应用程序,但我不知道为此目的使用了哪些组件...

我认为你做不到。但是您可以通过将一个空白按钮作为多视图的子项并添加一个单独的 TText 对象作为窗体的子项(或绝对不透明度为 1 的其他对象)来实现效果,如下面的屏幕截图所示。例如,如果按钮可以移动或调整大小是不理想的,但这可以通过创建,比如说,一个 TPanel,使 Multiview 和文本分开它的子项,然后使用面板来移动和调整大小来克服,这将确保按钮及其关联的文本保持一致。

编辑

鉴于 Tom Brunsberg 的评论,我建议将两者都设为 TPanel 的子项,而不是 TForm 的子项。当然,在我的测试中,他提到的 TText 向后移动的问题在完成后不会发生。关于将 TText 对象的 HitTest 设置为 false,他是完全正确的。

而不是 TMultiView,使用 TRectangle 作为菜单的基础。将其 Align 设置为左​​侧,将 Fill.Color 设置为 FFFFFFF。前两个十六进制数字 (7F) 定义 alpha 通道(半透明),其余的十六进制数字 (FFFFFF) 定义 RGB 颜色。这允许您将 Opacity 保留为一个,但仍然具有半透明效果。 TMultiView 控件无法做到这一点。

对于每个项目,使用 TLayoutTImageTText 以及您喜欢的任何分隔线。使用正常的 Align 属性来设置项目。

最后,为 TLayout 设置 HitTest = True,为 TImageTText 控件设置 HitTest = False。这是为了启用鼠标点击或点击。

以下是我的测试,包括 .fmx 内容(已删除图像数据)和快照。

  object Rectangle1: TRectangle
    Align = Left
    Fill.Color = x7FFFFFFF
    Size.Width = 200.000000000000000000
    Size.Height = 210.000000000000000000
    Size.PlatformDefault = False
    object Layout1: TLayout
      Align = Top
      HitTest = True
      Size.Width = 200.000000000000000000
      Size.Height = 50.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 0
      object Image1: TImage
        MultiResBitmap.Height = 128
        MultiResBitmap.Width = 128
        MultiResBitmap = <
          item
            Width = 128
            Height = 128
            PNG = {}
            FileName = 'C:\tmp\Imgs[=10=].bmp'
          end>
        Align = Left
      end
      object Text4: TText
        Align = Left
        Position.X = 50.000000000000000000
        Size.Width = 151.000000000000000000
        Size.Height = 50.000000000000000000
        Size.PlatformDefault = False
        Text = 'Zero Hero'
        TextSettings.Font.Size = 21.000000000000000000
        TextSettings.Font.StyleExt = {00070000000000000004000000}
        TextSettings.FontColor = claDarkblue
      end
    end
    object Layout2: TLayout
      Align = Top
      HitTest = True
      Position.Y = 50.000000000000000000
      Size.Width = 200.000000000000000000
      Size.Height = 50.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 1
      object Image2: TImage
        MultiResBitmap.Height = 128
        MultiResBitmap.Width = 128
        MultiResBitmap = <
          item
            Width = 128
            Height = 128
            PNG = {}
            FileName = 'C:\tmp\Imgs.bmp'
          end>
        Align = Left
      end
      object Text5: TText
        Align = Left
        Position.X = 50.000000000000000000
        Size.Width = 151.000000000000000000
        Size.Height = 50.000000000000000000
        Size.PlatformDefault = False
        Text = 'One More'
        TextSettings.Font.Size = 21.000000000000000000
        TextSettings.Font.StyleExt = {00070000000000000004000000}
        TextSettings.FontColor = claDarkblue
      end
    end
    object Layout3: TLayout
      Align = Top
      HitTest = True
      Position.Y = 100.000000000000000000
      Size.Width = 200.000000000000000000
      Size.Height = 50.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 2
      OnClick = Layout3Click
      OnMouseDown = Layout3MouseDown
      object Image3: TImage
        MultiResBitmap.Height = 128
        MultiResBitmap.Width = 128
        MultiResBitmap = <
          item
            Width = 128
            Height = 128
            PNG = {}
            FileName = 'C:\tmp\Imgs.bmp'
          end>
        Align = Left
        HitTest = False
      end
      object Text6: TText
        Align = Left
        HitTest = False
        Position.X = 50.000000000000000000
        Size.Width = 150.000000000000000000
        Size.Height = 50.000000000000000000
        Size.PlatformDefault = False
        Text = 'Double Joy'
        TextSettings.Font.Size = 21.000000000000000000
        TextSettings.Font.StyleExt = {00070000000000000004000000}
        TextSettings.FontColor = claDarkblue
      end
    end
    object Layout4: TLayout
      Align = Top
      HitTest = True
      Position.Y = 150.000000000000000000
      Size.Width = 200.000000000000000000
      Size.Height = 50.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 3
      object Image4: TImage
        MultiResBitmap.Height = 128
        MultiResBitmap.Width = 128
        MultiResBitmap = <
          item
            Width = 128
            Height = 128
            PNG = {}
            FileName = 'C:\tmp\Imgs.bmp'
          end>
        Align = Left
        HitTest = False
      end
      object Text1: TText
        Align = Left
        HitTest = False
        Position.X = 50.000000000000000000
        Size.Width = 151.000000000000000000
        Size.Height = 50.000000000000000000
        Size.PlatformDefault = False
        Text = 'Triple Fun'
        TextSettings.Font.Size = 21.000000000000000000
        TextSettings.Font.StyleExt = {00070000000000000004000000}
        TextSettings.FontColor = claDarkblue
      end
    end
  end