- // Get the favorite icon.
- val favoriteIconBitmap = nestedScrollWebView.getFavoriteIcon()
-
- // Get the default favorite icon drawable. `ContextCompat` must be used until API >= 21.
- val defaultFavoriteIconDrawable = ContextCompat.getDrawable(requireContext(), R.drawable.world)
-
- // Cast the favorite icon drawable to a bitmap drawable.
- val defaultFavoriteIconBitmapDrawable = (defaultFavoriteIconDrawable as BitmapDrawable)
-
- // Store the default icon bitmap.
- val defaultFavoriteIconBitmap = defaultFavoriteIconBitmapDrawable.bitmap
-
- // Set the favorite icon as the dialog icon if it exists.
- if (favoriteIconBitmap.sameAs(defaultFavoriteIconBitmap)) { // There is no website favorite icon.
- // Set the icon.
- dialogBuilder.setIcon(R.drawable.ssl_certificate)
- } else { // There is a favorite icon.
- // Create a drawable version of the favorite icon.
- val favoriteIconDrawable: Drawable = BitmapDrawable(resources, favoriteIconBitmap)
-
- // Set the icon.
- dialogBuilder.setIcon(favoriteIconDrawable)
- }