To indicate that a button opens an external link, you typically want an icon that suggests "externality" or "linking out". Android provides a variety of drawables through its android:drawable resources, but for indicating an external link, there isn't a single, universally recognized icon that is guaranteed to be present across all Android versions with the same appearance. However, here are a few approaches you can take, considering the standard Android resources and best practices for indicating external links:
1. Using a Standard Android Icon (if available):
As of my last update, there isn't a specific standard Android drawable that is widely recognized or recommended for "external link" across all Android versions. Icons like android:drawable/ic_menu_info_details or similar might not clearly convey the "external link" meaning.
2. Material Design Icons (Recommended):
Google recommends using Material Design icons for consistency across platforms. While not part of the traditional android:drawable resources, you can easily integrate Material Icons into your project. For an external link, you might use:
- "open_in_new" (or its variations like
open_in_new_outlined, open_in_new_rounded, open_in_new_sharp, depending on your design style)
How to use Material Icons:
a. Add the dependency to your build.gradle (Module: app) if you haven't already:
implementation 'com.google.android.material:material:1.4.0' // Check for the latest version
b. Use in XML:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Visit Website"
android:drawableRight="@drawable/ic_open_in_new_24dp"
android:drawableTint="@color/your_color_here" // Optional
android:drawablePadding="8dp" /> // For spacing between text and icon
c. Download the "open_in_new" icon from the Material Design Icons website and place it in your project's res/drawable folder, naming it appropriately (e.g., ic_open_in_new_24dp.xml for vector or ic_open_in_new_24dp.png for raster, considering density folders for different sizes).
3. Custom Drawable:
If you prefer a custom look or the Material Design approach doesn't fit your app's style, design your own "external link" icon. Ensure it's clear, simple, and recognizable. Place your custom icon in the appropriate density folders within res/drawable.
Example with a Custom Drawable (assuming you have ic_external_link.xml or ic_external_link.png in your drawables):
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Visit Website"
android:drawableRight="@drawable/ic_external_link"
android:drawablePadding="8dp" />
Note:
- Always ensure your icon is accessible by providing a clear text description of the button's action, either through the
android:text attribute or content description for screen readers.
- The appearance of built-in drawables can change between Android versions, so if consistency is crucial, using Material Design Icons or a custom drawable might be preferable.