Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vizbee/c6b0ffdbf73f92c05fa7b5d83e5aad28 to your computer and use it in GitHub Desktop.
Save vizbee/c6b0ffdbf73f92c05fa7b5d83e5aad28 to your computer and use it in GitHub Desktop.

Scenario

Show the cast icon in light/dark theme as per the corresponding appearance setting on the user's device

  1. In Android, the cast icon will be part of the application's Activity, hence, the styling (color) can be provided by application's style file.
  2. Define the style item vzb_castIconColor in the app-style.xml as shown below.
  3. Create 2 colors.xml files, one in res/values folder and another in res/values-night folder.
  4. Now, define colorCastIcon items and set values to match light/dark theme as shown below. These values are picked based on the device's light/dark theme settings.

Example

remote button cast icon color

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<resources>
<style name="Theme.AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="vzb_castIconColor">@color/colorCastIcon</item>
...
</style>
</resources>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<resources>
...
<color name="colorCastIcon">#FFFFFF</color>
...
</resources>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<resources>
...
<color name="colorCastIcon">#000000</color>
...
</resources>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.reactnativeappexample">
...
<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="true" android:theme="@style/Theme.AppTheme">
<activity android:name=".MainActivity"
android:theme="@style/Theme.AppTheme">
</activity>
</application>
</manifest>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment