Jump to content
Feniks888

How to Set contentDescription for TImage Component in Delphi FMX for Google Accessibility?

Recommended Posts

Hello everyone,

I'm currently working on a Delphi FMX application and need to improve its accessibility features for interactive elements. Specifically, I want to set the contentDescription for a TImage component, so that it can be properly identified by Google accessibility programs, allowing visually impaired users to interact with it effectively.

Could someone please guide me on how to set the contentDescription for an existing TImage component on my form? Any examples or best practices for implementing accessibility in Delphi FMX would be greatly appreciated!

Thank you in advance for your help!

Share this post


Link to post
3 hours ago, Lajos Juhász said:

Я вважаю, що це все ще така ситуація. 

 

Thank you for your response.

Share this post


Link to post
Posted (edited)

Maybe that can give some ideas, although for Win and VCL.
https://stackoverflow.com/questions/38273974/delphi-components-and-screen-readers

Perhaps this can be implemented in similar ways on Android too?  But I doubt it will be already well prepared under FMX, habe not checked recently.

 

Edit:

 

Maybe you can check, if this might work for you ( untested ) :
But I doubt that the Delphi handle works as expected.

 

uses
  System.SysUtils,
  FMX.Types,
  FMX.Controls,
  FMX.Platform,
  FMX.Platform.Android,
  Androidapi.JNI.GraphicsContentViewText, 
  Androidapi.Helpers, 
  Androidapi.JNI.Widget;
  
...  

procedure SetControlAccessibilityDescription(AControl: TControl; const ADescription: string);
var
  NativeView: JView;
begin
  NativeView := WindowHandleToPlatform(AControl.Handle).View;

  if NativeView <> nil then
  begin
    NativeView.setContentDescription(StringToJString(ADescription));
  end
  else
  begin
    raise Exception.Create('Das View-Objekt konnte nicht abgerufen werden.');
  end;
end;

...

// Application for Label
SetControlAccessibilityDescription(Label1, 'Das ist eine Beschriftung für den Namen');

...

// Application for Edit
SetControlAccessibilityDescription(Edit1, 'Bitte geben Sie Ihren Namen ein');


...

// Application for Checkbox
SetControlAccessibilityDescription(CheckBox1, 'Ich akzeptiere die Nutzungsbedingungen');

...

// Application for Switch
SetControlAccessibilityDescription(Switch1, 'Benachrichtigungen ein- oder ausschalten');

 

 

Edited by Rollo62

Share this post


Link to post

Thank you very much for the code, I'll try it today and let you know if it worked.

Share this post


Link to post
On 10/4/2024 at 4:02 PM, Rollo62 said:

NativeView := WindowHandleToPlatform(AControl.Handle).View;

This part will not even compile. TControl does not have a Handle property in FMX.

On 10/4/2024 at 4:02 PM, Rollo62 said:

NativeView.setContentDescription(StringToJString(ADescription));

Nor will this. setContentDescription takes a JCharSequence as the parameter.

The main problem is that "non-native" FMX controls do not have an underlying native control, except when ControlType is Platform. Even then, there is no support for calling setContentDescription on that native control. This would require adding a ContentDescription property to TControl so that it can be passed to the underlying "native" controls. On top of this, only certain controls on Android support ControlType of Platform.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×