Ad Options
AdOption and AdBadgeOption configure advertisement display and badge appearance for video ads. These options control ad loading behavior and the visual presentation of ad badges.
Overview
AdOption configures:
Ad fetch timeout
VAST attributes for ad delivery
AdBadgeOption configures:
Badge text ("Ad" or "Sponsored")
Badge colors and styling
Badge visibility on thumbnails and player
Custom typeface
Creating Ad Options
Using Builder
val adOption = AdOption.Builder()
.adsFetchTimeoutInSeconds(10)
.build()
val adBadgeOption = AdBadgeOption.Builder()
.adBadgeTextColor(Color.WHITE)
.adBadgeBackColor(Color.parseColor("#F65178EE"))
.adBadgeLabel(AdBadgeTextType.SPONSORED)
.adBadgeIsHidden(false)
.build()Using DSL (Recommended)
val viewOptions = viewOptions {
adOptions {
adsFetchTimeoutInSeconds(10)
vastAttributes(mapOf("key" to "value"))
}
adBadgeOptions {
adBadgeTextColor(Color.WHITE)
adBadgeBackColor(Color.parseColor("#F65178EE"))
adBadgeLabel(AdBadgeTextType.SPONSORED)
adBadgeIsHidden(false)
adBadgeShowOnThumbnails(true)
}
}AdOption Properties
adsFetchTimeoutInSeconds
Type: Int
Default: 10 seconds
Maximum time to wait for ad content to load before timing out.
adOptions {
adsFetchTimeoutInSeconds(15) // Wait up to 15 seconds
}vastAttributes
Type: Map<String, String>
Default: Empty map
Custom attributes to pass with VAST ad requests.
adOptions {
vastAttributes(
mapOf(
"app_name" to "MyApp",
"user_segment" to "premium"
)
)
}AdBadgeOption Properties
adBadgeTextColor
Type: Int (color)
Default: White (Color.WHITE)
Text color for the ad badge.
adBadgeOptions {
adBadgeTextColor(Color.WHITE)
}adBadgeBackColor
Type: Int (color)
Default: Blue (0xF65178EE)
Background color for the ad badge.
adBadgeOptions {
adBadgeBackColor(Color.parseColor("#F65178EE"))
// or
adBadgeBackColor(Color.parseColor("#FF5722"))
}adBadgeLabel
Type: AdBadgeTextType (enum)
Default: SPONSORED
Text displayed on the ad badge.
Values:
AdBadgeTextType.SPONSORED- Displays "Sponsored"AdBadgeTextType.AD- Displays "Ad"
adBadgeOptions {
adBadgeLabel(AdBadgeTextType.AD)
}adBadgeIsHidden
Type: Boolean
Default: false
Show or hide the ad badge.
adBadgeOptions {
adBadgeIsHidden(false) // Show badge
}adBadgeShowOnThumbnails
Type: Boolean
Default: false
Show ad badge on video thumbnails in the feed.
adBadgeOptions {
adBadgeShowOnThumbnails(true) // Show on thumbnails
}adBadgeTypeface
Type: Typeface
Default: Typeface.DEFAULT
Custom typeface for ad badge text.
val customFont = ResourcesCompat.getFont(context, R.font.custom_font)
adBadgeOptions {
adBadgeTypeface(customFont)
}Default Values
AdOption Defaults
adsFetchTimeoutInSeconds
10
vastAttributes
Empty map
AdBadgeOption Defaults
adBadgeTextColor
White
adBadgeBackColor
0xF65178EE (blue)
adBadgeLabel
SPONSORED
adBadgeIsHidden
false
adBadgeShowOnThumbnails
false
adBadgeTypeface
Typeface.DEFAULT
Complete Examples
Standard Ad Configuration
val viewOptions = viewOptions {
adOptions {
adsFetchTimeoutInSeconds(10)
}
adBadgeOptions {
adBadgeTextColor(Color.WHITE)
adBadgeBackColor(Color.parseColor("#F65178EE"))
adBadgeLabel(AdBadgeTextType.SPONSORED)
adBadgeShowOnThumbnails(true)
}
}Custom Styled Ad Badge
class AdFeedActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_ad_feed)
val videoFeedView = findViewById<FwVideoFeedView>(R.id.videoFeedView)
val viewOptions = viewOptions {
baseOptions {
feedResource(FeedResource.Discovery)
}
adOptions {
adsFetchTimeoutInSeconds(15)
}
adBadgeOptions {
adBadgeTextColor(Color.BLACK)
adBadgeBackColor(Color.parseColor("#FFD600")) // Yellow
adBadgeLabel(AdBadgeTextType.AD)
adBadgeIsHidden(false)
adBadgeShowOnThumbnails(true)
}
}
videoFeedView.init(viewOptions)
}
}Minimal Ad Badge
val viewOptions = viewOptions {
adBadgeOptions {
adBadgeTextColor(Color.WHITE)
adBadgeBackColor(Color.parseColor("#80000000")) // Semi-transparent
adBadgeLabel(AdBadgeTextType.AD)
adBadgeShowOnThumbnails(false) // Only in player
}
}Branded Ad Badge
val brandFont = ResourcesCompat.getFont(context, R.font.brand_font)
val viewOptions = viewOptions {
adBadgeOptions {
adBadgeTextColor(Color.WHITE)
adBadgeBackColor(Color.parseColor("#FF3700B3")) // Brand color
adBadgeLabel(AdBadgeTextType.SPONSORED)
adBadgeShowOnThumbnails(true)
adBadgeTypeface(brandFont)
}
}High Contrast Ad Badge
val viewOptions = viewOptions {
adBadgeOptions {
adBadgeTextColor(Color.BLACK)
adBadgeBackColor(Color.WHITE)
adBadgeLabel(AdBadgeTextType.AD)
adBadgeIsHidden(false)
adBadgeShowOnThumbnails(true)
}
}Hidden Ad Badge
val viewOptions = viewOptions {
adBadgeOptions {
adBadgeIsHidden(true) // No badge displayed
}
}Quick Timeout for Fast Loading
val viewOptions = viewOptions {
adOptions {
adsFetchTimeoutInSeconds(5) // Fast timeout
}
adBadgeOptions {
adBadgeShowOnThumbnails(true)
}
}Ad Badge Visibility
The ad badge can appear in two locations:
On Thumbnails
adBadgeOptions {
adBadgeShowOnThumbnails(true)
}Shows the badge on video thumbnails in the feed, helping users identify sponsored content before clicking.
In Player
The badge always shows in the video player (unless adBadgeIsHidden is true).
adBadgeOptions {
adBadgeShowOnThumbnails(false) // Only in player, not on thumbnails
}Ad Badge Text Options
"Sponsored" Label
adBadgeOptions {
adBadgeLabel(AdBadgeTextType.SPONSORED)
}Displays "Sponsored" - typically used for sponsored content and brand partnerships.
"Ad" Label
adBadgeOptions {
adBadgeLabel(AdBadgeTextType.AD)
}Displays "Ad" - typically used for direct advertisements.
Ad Loading Behavior
Timeout Configuration
adOptions {
// Short timeout for fast user experience
adsFetchTimeoutInSeconds(5)
// Medium timeout (default)
adsFetchTimeoutInSeconds(10)
// Long timeout for slower connections
adsFetchTimeoutInSeconds(20)
}Shorter timeouts improve perceived performance but may miss some ads
Longer timeouts ensure more ads load but may delay content display
Default of 10 seconds balances performance and ad delivery
VAST Attributes
adOptions {
vastAttributes(
mapOf(
"app_id" to "com.myapp",
"user_id" to userId,
"content_category" to "technology",
"gdpr_consent" to "true"
)
)
}Custom attributes passed to VAST ad server for targeting and compliance.
Important Notes
Ad badges help maintain transparency about sponsored content
Badge visibility is separate for thumbnails and player
Typeface must be included in your app's font resources
Ad fetch timeout affects initial feed loading time
VAST attributes can be used for ad targeting and compliance
Badge colors should maintain sufficient contrast for readability
Consider platform advertising guidelines when configuring badges
Ad configuration is applied globally across the app
See Also
ViewOptions Overview - Complete configuration system
Video Ads Support - Ad implementation details
FwVideoFeedView - Video feed configuration
BaseOption - Content sources including ads
Last updated