Top
Tag Android Views
  • 22 Aug 2024
  • 1 Minute To Read
  • Dark
    Light
  • PDF

Tag Android Views

  • Dark
    Light
  • PDF

Article summary

Why should you tag Android views?

The Whatfix Mobile SDK uniquely identifies the screen of native apps with the properties of a UI element like resource-id, tag, content-description, etc. on the screen. Adding any of these properties helps in identifying the element and hence the app screen more accurately.

How to add a resource-id to any view?

A resource-id is a unique identifier for any view. It can be added via XML.


<Button
        android:id="@+id/btn_ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Ok">
</Button>


How to add a tag to a view?

Tags are extra information associated with a view. A tag can be added in two ways:

  • Using Java
  • Using XML

Using Java

button.setTag("tag_btn_ok");

Using XML

<Button
        android:tag="tag_btn_ok"
        android:id="@+id/btn_ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Ok">
</Button>

How to add content-description to a view?

The content-description describes the purpose of a particular view.

your title goes here

For more information on content-description, see Describe each UI element.

The content-description attribute can be added in two ways:

  • Using Java
  • Using XML

Using Java

imageView.setContentDescription("Arrow Icon");

Using XML

<ImageView
        android:contentDescription="Arrow Icon"
        android:tag="tag_img_arrow_icon"
        android:id="@+id/img_arrow_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/arrow_icon">
</ImageView>

Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.