0

There is a post of the same question and it has received an answer. I suspect my case is different and it may indicate a general problem of the project configuration. windowTranslucentNavigation is for API 19. I have set targetSdkVersion inn both build.gradle and manifests. In build.gradle:

defaultConfig {
applicationId "xxx"
minSdkVersion 9
targetSdkVersion 21
// Enabling multidex support.
multiDexEnabled true

}

In manifests:

<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="21" />

Android Studio clearly knows about windowTranslucentNavigation. The following warning shows this: windowTranslucentNavigation warning

When the project is built, the following error is generated:

Error:(7, 29) No resource found that matches the given name: attr 'windowTranslucentNavigation'.

Here is the contents of themes.xml:

<resources>
<!-- the theme applied to the application or activity -->
<style name="OverlayingActionBarTheme"
    parent="@style/Theme.AppCompat">
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:actionBarStyle">@style/TransparentActionBar</item>
    <item name="android:windowTranslucentNavigation">true</item>
    <!-- Support library compatibility -->
    <item name="windowActionBarOverlay">true</item>
    <item name="actionBarStyle">@style/TransparentActionBar</item>
    <item name="windowTranslucentNavigation">true</item>
</style>
<!-- ActionBar styles -->
<style name="TransparentActionBar"
    parent="@style/Widget.AppCompat.ActionBar">
    <item name="android:background">@color/black_overlay</item>

    <!-- Support library compatibility -->
    <item name="background">@color/black_overlay</item>
</style>

Could anyone offer a tip on how to fix this?

Community
  • 1
  • 1
Hong
  • 17,643
  • 21
  • 81
  • 142

2 Answers2

2

The answer that suggests you change your minSdkVersion to support this is not entirely correct. The feature may not be supported on versions older than 19, but you can use it without changing your minSdkVersion.

You would create a themes.xml file in a folder named values-v19. This will allow you to use SDK 19+ style/theme features on any device that is running that version or above.

More info about how this works: Supporting Different Platform Versions.

Austyn Mahoney
  • 11,398
  • 8
  • 64
  • 85
  • Thanks a lot for the tip. As described in my original question, I need a custom theme (OverlayingActionBarTheme). How can I use windowTranslucentNavigation for API+ in addition to OverlayingActionBarTheme for API19+? – Hong Feb 03 '15 at 01:56
  • 1
    There are a lot of questions already answering how to have a base theme, with an extension on later versions. One example: http://stackoverflow.com/questions/9140085/different-theme-for-different-android-sdk-versions – Austyn Mahoney Feb 03 '15 at 20:10
1

You'll need to change your minSdkVersion to 19 if you want to support that, or not use it. In any other circumstance, for example calling a method only supported in a new version, you can programmatically decide not to call it if your version is lower, but in this case you can't change the style programmatically depending on the version.

Antonio MG
  • 20,382
  • 3
  • 43
  • 62
  • Thanks a lot for your quick answer. I added the contents of thems.xml after reading your answer. You can see there are two items (windowActionBarOverlay and actionBarStyle) that are supported in API11 and above. They have been working without any problem even though minSdkVersion is 9. I am wondering why windowTranslucentNavigation is not the case. – Hong Jan 29 '15 at 16:07
  • 1
    Those properties are included in the AppCompat library. – Antonio MG Jan 29 '15 at 16:08
  • I see. Is there an easy way to find out what is in the support library. I took a look at https://developer.android.com/tools/support-library/features.html, it is too general. – Hong Jan 29 '15 at 16:24