Search code examples
androidandroid-theme

Android: How to disable app theme being applied to a particular view?


I have a 3rd party video player view defined in my fragment XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true"
        android:focusable="true"
        android:orientation="vertical">

    <com.3rdPartyView
            android:id="@+id/videoPlayerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
</LinearLayout>

The view's background is being overridden by my theme that in result hides the video being played. I can't seem to not have the view's background be set by my theme.

I've tried setting the following on the view itself, as well as on its outer linear layout:

app:theme="@android:style/Theme.Holo.Light"
android:theme="@android:style/Theme.Holo.Light"
android:background="@null"

I've also tried manually adding the view after the fragment has been inflated, but with no luck: the view comes with its background changed.

I'm certain this is the case since, I've commented out my main theme's attr: android:background in its definition and was able to see the video.


Solution

  • One may hardcode theme upon a view by:

    <View ...
      android:theme="@style/ThemeOverlay.MaterialComponents.Dark"/>
    

    That 3rd party view I was using perhaps wasn't written properly.