Failed to find style 'mapViewStyle' in cur

2019-01-07 23:13发布

问题:

I am making an app which uses google maps. But in my xml I get th error "Failed to find style 'mapViewStyle' in current theme." Instead I have given onternet permission and used the google maps library inside the application tag.

Can anybody help me over this.

Thanks a lot

following is my xml file...

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/hello"
        />
  <com.google.android.maps.MapView
    android:id="@+id/mapview1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:enabled="true"
    android:clickable="true"
    android:apiKey="0ACHOtlugQlOP_-siR3LLyIBjv1SwpKWimIY8jw" />
</Relativelayout>

回答1:

My answer may be a late one, but i hope that it'll deals with the actual reason and sure it could be helpful for those who are going to search about the same problem in future.

This type of errors,

1. Android Google Maps Failed to find style 'mapViewStyle' in current theme
2. Failed to find style 'imageButtonStyle' in current theme 
3. Failed to find style 'editTextStyle' in current theme 
4. Failed to find style 'textViewStyle' in current theme 

Anything from the above list it may be,

The ultimate reason is ,

We have selected the unavailable Theme for the layout.

This may cause because of,

  1. The selected theme is not available in themes.xml file.
  2. The selected theme is belongs to higher version sdk, but our current target sdk is lower one.

This problem mostly happens,

  1. when you copy the whole layout file and try to implement it in your project. a. Your may forgot to copy themes.xml file b. You may have lower target sdk, the original layout created with higher target sdk.

The Solutions for this problem are,

(Open and View the layout file in the Graphical Layout View, and look at the top Right corner. There your themes for the layout have been selected.)

  1. So click the dropdown list for theme selection and choose the available themes according to your project themes and targeted sdk themes. (OR)
  2. If the theme is a custom one , if you are required it , then copy the themes.xml file to your project from the source where you copied the layout xml file. (OR)
  3. If the theme is sdk avail theme, if you are required it , then change your target according to your selected theme.

Hope,This might be helpful for somebody.



回答2:

Not sure why, but if you add an explicit style and define that in /values/styles.xml this error will go away.

styles.xml:

<style name="mapView">
    <item name="android:gravity">center</item>
</style>

and the layout:

<com.google.android.maps.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="YOUR_API_KEY"
    android:visibility="visible"
    style="@style/mapView"
/>

Seems like com.google.android.maps.MapView really wants a style of some sort to be declared.



回答3:

Another reason for these errors might actually be an internal eclipse error.

In that case what does solve it is:

  1. closing the xml layout file
  2. restarting eclipse (or even ADT as I heard it happens there as well)

It usually is worth a try (esp. when you encounter this error "out of the blue"), since it does not take a lot of time. Although for the OP it might not be the case, this could still help someone else searching.



回答4:

You need to change only Android 2.2 to android 3.0, and also give id and user-permissions and child of application



回答5:

Every android theme is not suitable for every type of view. Because of this we should select one of the suitable themes for our view type.

Here is how problems looks
If theme is not suitable it will give us missing styles error.



Here is the solution
1.Firstly select theme bar.

2.Select theme for your view

3.After selecting theme then press ok.
If the theme is suitable for your view it will render if not then select another theme and try until you find a suitable theme for your application.
Whenever your theme is suitable it will render as like the picure below.



回答6:

If you are using Android 3.0 and above on your Graphical Layout. Try changing it to Android 2.2 or 2.3.



回答7:

This error happens due to the fact that some icons or property are missing for mapViewStyle. If you have ever applied any custom theme on android device then you might have faced error like "missing assets" or "theme improperly compiled" etc. These error arises due to lack for icons or layout for each and every look of phone such as button, menus, status bar etc.

Similar is the case with the mapViewStyle. During the project creation you might have selected a default theme for your application. This theme is missing certain components for mapViewStyle such button icon or style (Just giving the idea, I don't know if this is true or not). I think you might have understood the point.

Now to remove the error go into res>values>styles.xml

remove the previous theme line and put this one

<style name="AppBaseTheme" parent="android:Theme.Light">

The above example is just for making you understand and give you a broad idea of the problem. I don't state that it's 100% true.

if this answer is useful then mark it as useful.



回答8:

Make sure you have added your custom theme part in all other styles.xml present under different values folder under res.

I had similar problem. In my case I had added a custom theme in values-large folder under res. And it was working at runtime but giving error as yours in eclipse. So i tried adding the custom part(in my case totally there was 3 tags added to styles.xml file) in all other styles.xml file. i.e. styles.xml files under values-normal-hdpi, values-normal-mdpi, valuse-v11 and values-v14... And BOOM!!! It solved my problem which wasted my whole day.



回答9:

Make sure your all other styles.xml present under different values contains your custom theme part.

I had similar problem.

In my case I had added a custom theme in values-large folder under res. And it was working at runtime but giving error as yours in eclipse.

So i tried adding the custom part(in my case totally there was 3 tags added to styles.xml file) in all other styles.xml file. i.e. styles.xml files under values-normal-hdpi, values-normal-mdpi, valuse-v11 and values-v14...

And BOOM!!! It solved my problem which wasted my whole day.



回答10:

While I'm sure this won't work for everyone, but for me I simply changed the Theme in the Preview Window to Theme.AppCompat.Light.

It seems the in some cases merely setting the correct theme is the solution. Which theme out of all those choices? Go for the compatibility themes first; after that, good luck!



回答11:

Refresh the xml layout by click Refresh button on Preview or close the xml then open it again fix my problem



标签: android maps