Joel Page
Joel Page

Reputation: 642

Setting primary color for Android Wear app

I am creating an android wear app and am trying to set it's primary color. I create and set a theme the same way as for a mobile app. Every attribute is changed correctly except for the primary color. It will always be the default teal color that android uses. I am using the same theme on the companion app and it works there. Is there something I am missing that is done differently in wear? Is there something that could override this setting?

I have tried changing the parent theme to material or Compact.app.

Android Manifest:

    <application
    android:name="com.turndapage.navmedia.App"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.Nav">

styles.xml

<resources>
<style name="Theme.Nav" parent="@android:style/Theme.DeviceDefault">
    <!-- your app branding color for the app bar -->
    <item name="colorPrimary">@color/primary</item>
    <!-- darker variant for the status bar and contextual app bars -->
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <!-- theme UI controls like checkboxes and text fields -->
    <item name="colorAccent">@color/accent</item>
    <item name="android:colorForeground">@color/primary</item>
    <item name="android:colorBackground">@color/Viewport_Background</item>
</style>

colors.xml

<resources>
<color name="primary">#8c6354</color>
<color name="Viewport_Background">#4d362e</color>
<color name="primary_dark">#66483d</color>
<color name="Action">#a67563</color>
<color name="accent">#a1887f</color>
<color name="Background_Shaded">#000000</color>
<color name="background">#000000</color>
<color name="digital_text">#ffffff</color>

Upvotes: 1

Views: 1198

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 200040

You need to use the android: prefix versions:

<style name="Theme.Nav" parent="@android:style/Theme.DeviceDefault">
  <!-- your app branding color for the app bar -->
  <item name="android:colorPrimary">@color/primary</item>
  <!-- darker variant for the status bar and contextual app bars -->
  <item name="android:colorPrimaryDark">@color/primary_dark</item>
  <!-- theme UI controls like checkboxes and text fields -->
  <item name="android:colorAccent">@color/accent</item>
  <item name="android:colorForeground">@color/primary</item>
  <item name="android:colorBackground">@color/Viewport_Background</item>
</style>

The non-namespaced verisons are used by AppCompat, which is not needed or used on Android Wear (Theme.DeviceDefault extends Theme.Material on Wear devices).

The colorPrimary is not used in any surfaces by default, so you'd still need to manually reference it via ?android:attr/colorPrimary for the background of a view for instance.

Note that you cannot change the background color of notifications in the stream as per this post - however, the notification color will be used when the user taps into the notification (assuming you haven't set a content intent - in those cases, they'll just go into your app).

Upvotes: 0

Related Questions