2

In my current project, when I select the Design tab in Android Studio 2.2.2 for a particular layout I get an error that says

Missing styles. Is the correct theme chosen for this layout?

and it goes on to say

Failed to find style 'textEditSuggestionItemLayout' in current theme (42 similar errors not shown)

But, the actual layout renders OK in the Designer and at runtime.

There are lots of other S.O. posts on this, such as here and here and most of the answers seem to involve clearing the caches and restarting Android Studio, or selecting a different theme from the dropdown. I I have tried the first one but it didn't help. I haven't tried the second one yet because I don't really understand what a theme is.

Questions:

  1. The error implies that there's an error in the theme itself. What is that? Is the theme file part of my project, i.e., is it one that I should be creating, editing, and that gets built and shipped as part of my APK or is it only used in the developer IDE?
  2. If I select a different theme from the dropdown how do I know what the "correct" one is?
  3. Since my project builds and runs OK as is, can I just ignore these errors? In other words are these errors in my code or just a problem with the development environment?

Edit: Some additional information after responding to comments, below:

The only place the string 'theme' is used in my manifest is

  android:theme="@style/Theme.FullScreen"

... and FullScreen is the theme specified in the dropdown.

I did a search in my project for the string "textEditSuggestionItemLayout" and Android Studio found no occurrences of it.

Community
  • 1
  • 1
user316117
  • 7,971
  • 20
  • 83
  • 158
  • Are you sure it says `textEditSuggestionItemlayout` and not `textEditSuggestionItemLayout`? (capital `L`) http://stackoverflow.com/a/37798090/2308683 – OneCricketeer Dec 02 '16 at 20:46
  • It used the capital "L" and that's what I did my search on. I've fixed that, above – user316117 Dec 02 '16 at 21:19

2 Answers2

0

If you've recently updated AS or any of its components, then try to 'Invalidate caches & restart'.

Else, try choosing AppTheme from the Design tab or change it to AppTheme from the default one. Choose the one that conforms to your parent app theme in your styles.xml.

The cause of the error could be anything from malfunctioning IDE to selecting a theme not mentioned in your styles.xml (most likely).

AlphaQ
  • 656
  • 8
  • 18
  • As I said in the OP, I already tried invalidating the cache and restarting. And as I **also** said, I didn't want to try just selecting another theme without understanding more about what a theme is. – user316117 Dec 02 '16 at 20:33
  • @user316117 The error is occurring mostly because of the mismatch of the `AppTheme` with other themes that you have used in your layouts. Try using the same occurrences of the theme in your entire application. – AlphaQ Dec 03 '16 at 17:47
0

You could do a project-wide search for textEditSuggestionItemlayout, or the other styles that it claims to miss.

These are either in your own res/values/styles.xml and/or res/values/themes.xml files, or they are provided within the SDK, which is why you see some suggestions to uncheck 'Automatically Pick Best' and pick a version you have installed. In some cases, the latest API version's rendering tools don't work.

As an example, if you have your style set at Theme.Holo, but you are using the AppCompatActivity, you'll get a rendering error that you must use a Theme.AppCompat (or descendant). These themes are changeable from the dropdown of the design editor.

You can see what themes/styles are applied to your Activities within the AndroidManifest.xml.


res/values/styles.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/PrimaryColor</item>
    <item name="colorPrimaryDark">@color/PrimaryDarkColor</item>
    <!-- Customize your theme here. -->
</style>

AndroidManifest.xml

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

Note: android:theme= and @style/


If you are still missing themes, then you may be missing some dependency, such as

compile 'com.android.support:design:<your_version_here>' 

If your code runs fine, then sure, ignore it, but I think getting the layout designer working again shouldn't be ignored.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • But I still don't understand what a theme **IS**, even after reading: ( https://developer.android.com/guide/topics/ui/themes.html ...for example is there a default theme? Do I need to specify a theme? – user316117 Dec 02 '16 at 20:29
  • Yes, there is a default theme for the project. `res/values/styles.xml` is created and referenced for the application within the Manifest. It can be overridden at an activity-level as well – OneCricketeer Dec 02 '16 at 20:31
  • I still don't understand. Where you say "_or they are provided within the SDK, which is why you see some suggestions to uncheck 'Automatically Pick Best' and pick a version you have installed_." it implies that I've installed a theme. I haven't explicitly installed a theme. So how do I tell what a "correct" theme is and what makes a theme "incorrect"? – user316117 Dec 02 '16 at 20:39
  • An "incorrect" theme simply means the value cannot be found in the theme that is used. There are default themes that are provided by the SDK (such as `Theme.Holo`), then there are those provided by dependencies (`Theme.AppCompat)`, and your own within `res/values/styles.xml`. – OneCricketeer Dec 02 '16 at 20:41
  • I did a search and "textEditSuggestionItemlayout" is not found anywhere in my project. So if that string is not found in the theme used, as you explain above, and it's not in my project then where is Android Studio getting it from? – user316117 Dec 02 '16 at 20:47
  • Well, I think there should be a capital `L` in Layout, but if you are curious, then [here's all the values of the SDK](https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/styles.xml) – OneCricketeer Dec 02 '16 at 20:55
  • The only place the string theme is used in my manifest is _android:theme="@style/Theme.FullScreen"_ and FullScreen is the theme specified in the dropdown. I've updated my original question to reflect this. – user316117 Dec 02 '16 at 21:14
  • Are you sure you want a FullScreen theme? Have you tried any others? – OneCricketeer Dec 02 '16 at 23:42
  • Yes, I want a fullscreen theme - this is for a dedicated industrial application for a single-app device we ship as an accessory to some manufacturing equipment my company makes. Is that a problem? – user316117 Dec 02 '16 at 23:46
  • No, not a problem. Just that theme is missing a few of the styles of others, as evident by the "non-errors", since like you've said, the app runs. – OneCricketeer Dec 02 '16 at 23:48
  • Though, I think you want one of these. http://stackoverflow.com/a/16240427/2308683 ... `@style/Theme.FullScreen` is something you have defined in your app since it is not from `@android:style` – OneCricketeer Dec 02 '16 at 23:50