Android 让我们解决“Failed to find style 'mapViewstyle' in current theme”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12023940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:30:58  来源:igfitidea点击:

Let's solve the "Failed to find style 'mapViewstyle' in current theme" error

androideclipseandroid-layoutandroid-mapview

提问by Billdr

Sorry to post yet another one of these, but it seems we have yet to document every solution to this issue.

很抱歉再次发布其中一个,但似乎我们尚未记录此问题的所有解决方案。

Here's what happened: I added a mapview, everything was working peachy. I added a slidingdrawer and moved buttons into it, then changed the root node from a linear to a relative. Since then I get an error in the Graphical Layout of my main.xml class that reads

这是发生的事情:我添加了一个地图视图,一切都很好。我添加了一个滑动抽屉并将按钮移动到其中,然后将根节点从线性更改为相对。从那时起,我在 main.xml 类的图形布局中收到一个错误,该错误显示为

Missing styles. Is the correct theme chosen for this layout? Use the Theme combo box above the layout to choose a different layout, or fix the theme style references. Failed to find style 'mapViewStyle' in current theme.

缺少样式。是否为此布局选择了正确的主题?使用布局上方的主题组合框选择不同的布局,或修复主题样式引用。无法在当前主题中找到样式“mapViewStyle”。

Toggling the root node to linear and back to relative has gotten the map to display, but the error is still in the graphical layout.

将根节点切换为线性并返回到相对已使地图显示,但错误仍在图形布局中。

So far I have done the following solutions, which may resolve the issue for most cases:

到目前为止,我已经完成了以下解决方案,它们可以解决大多数情况下的问题:

  1. Added a style.xml to create a 'mapView' style.
  2. Verified my build target is API 2.3.3 (10)
  3. Made sure <uses-library android:name="com.google.android.maps"/>is a child node of Application.
  4. Clean/rebuilt my application.
  5. Deleted R.
  6. Deleted and rebuilt main.xml
  7. Restarted the adb server, Eclipse, my computer, and my device.
  8. Toggled between Android 3.0 and Android 2.3.3 in the Graphical Layout.
  1. 添加了 style.xml 以创建“mapView”样式。
  2. 验证我的构建目标是 API 2.3.3 (10)
  3. 确保<uses-library android:name="com.google.android.maps"/>是应用程序的子节点。
  4. 清理/重建我的应用程序。
  5. 删除了 R。
  6. 删除并重建 main.xml
  7. 重新启动 adb 服务器、Eclipse、我的电脑和我的设备。
  8. 在图形布局中在 Android 3.0 和 Android 2.3.3 之间切换。

However, my problem persists. Here's my layout xml.

但是,我的问题仍然存在。这是我的布局 xml。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >


<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    style="@style/mapView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:apiKey="asdf" //not my real key
    android:clickable="true" />

<!-- TODO: update the API key with release signature -->
<SlidingDrawer
    android:id="@+id/slidingDrawer1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:content="@+id/content"
    android:handle="@+id/handle" >

    <Button
        android:id="@+id/handle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Menu" />


    <LinearLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <Button
            android:id="@+id/about"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/about" />

        <Button
            android:id="@+id/record"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/record" />

        <Button
            android:id="@+id/start"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/start" />

    </LinearLayout>

</SlidingDrawer>
</RelativeLayout>

Here is my manifest xml.

这是我的清单 xml。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.myschoolhere"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <uses-library android:name="com.google.android.maps"/>
    <activity
        android:name=".GeoTagActivity"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

If anyone has a solution, please let me know. I'll do my best to post back if I ever figure it out.

如果有人有解决方案,请告诉我。如果我弄清楚了,我会尽力回帖。

回答by Kartihkraj Duraisamy

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 Themefor the layout.

我们选择了不可用Themelayout.

This may cause because of,

这可能是因为,

  1. The selected themeis not available in themes.xmlfile.
  2. The selected themeis belongs to higher version sdk, but our current target sdkis lower one.
  1. 所选文件themethemes.xml文件中不可用。
  2. 所选的theme是属于更高版本sdk,但我们当前的目标sdk是更低版本。

This problem mostly happens,

这个问题多半会出现

  1. when you copy the whole layoutfile and try to implement it in your project. a. Your may forgot to copy themes.xmlfile b. You may have lower target sdk, the original layoutcreated with higher target sdk.
  1. 当您复制整个layout文件并尝试在您的project. 一种。您可能忘记复制themes.xml文件 b。你可能有较低的target sdk,原来layout用较高的创造target sdk

The Solutions for this problem are,

这个问题的解决方案是,

(Openand Viewthe layoutfile in the Graphical Layout View, and look at the top Right corner. There your themesfor the layouthave been selected.)

打开查看 中layout文件Graphical Layout View,然后查看右上角。您themeslayout已被选中。)

  1. So click the dropdown list for themeselection and choose the available themesaccording to your project themesand targeted sdk themes. (OR)
  2. If the themeis a customone , if you are required it , then copy the themes.xmlfile to your project from the source where you copied the layout xmlfile. (OR)
  3. If the themeis sdkavail theme, if you are required it , then change your targetaccording to your selected theme.
  1. 因此,单击下拉列表进行theme选择,然后themes根据您的项目themestargeted sdk themes. (或者)
  2. 如果themecustom一个,如果您需要它,则将themes.xml文件从复制layout xml文件的源复制到您的项目。 (或者)
  3. 如果themesdk无济于事theme,如果你需要它,那么你改变target根据您的选择theme

Hope,This might be helpful for somebody.

希望,这可能对某人有帮助。

回答by Harun ERGUL

This solution is for Android Studio maybe it will give an idea for Eclipse user too.
Every android theme is not suitable for every view. Because of this we should select one of the suitable themes for our view type.

此解决方案适用于 Android Studio,也许它也会为 Eclipse 用户提供一个想法。
每个 android 主题并不适合每个视图。因此,我们应该为我们的视图类型选择合适的主题之一。

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

下面是问题的样子
如果主题不合适,它会给我们丢失样式错误。

enter image description here

Here is the solution
1.Firstly select theme bar.
enter image description here

在此处输入图片说明

这是解决方案 1.
首先选择主题栏。
在此处输入图片说明

2.Select theme for your view

2.为您的视图选择主题

enter image description here

在此处输入图片说明

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. enter image description here

3.选择主题后按确定。
如果主题适合您的视图,它将呈现,如果不适合,则选择另一个主题并尝试直到找到适合您的应用程序的主题。
只要您的主题合适,它就会呈现如下图所示。 在此处输入图片说明

回答by Nikhil

Click on Refresh button enter image description here

点击刷新按钮 在此处输入图片说明

Else Try Invalidate Caches and Restart

否则尝试使缓存无效并重新启动

回答by Pramod Solanky

I was facing a similar issue.

我面临着类似的问题。

I don't know what the problem was and after searching an answer on google I found nothing of help.

我不知道问题是什么,在谷歌上搜索答案后,我没有找到任何帮助。

So What I did was deleted the activity and guess what??, it worked.

所以我所做的是删除了活动,猜猜是什么??,它起作用了。

Again, I'm not sure how did this work out but it did eventually for me.

同样,我不确定这是如何解决的,但最终对我来说确实如此。

Hope this helps.

希望这可以帮助。

回答by margo

when you create android application,you choose minimum required sdk API14.And then,you will create project successfully.This is my solution.

创建android应用程序时,选择最低要求的sdk API14。然后,您将成功创建项目。这是我的解决方案。