【问题标题】:Let's solve the "Failed to find style 'mapViewstyle' in current theme" error让我们解决“无法在当前主题中找到样式'mapViewstyle'”错误
【发布时间】:2012-08-19 03:13:48
【问题描述】:

很抱歉再发布一个,但似乎我们还没有记录此问题的所有解决方案。

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

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

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

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

  1. 添加了 style.xml 以创建“mapView”样式。
  2. 已验证我的构建目标是 API 2.3.3 (10)
  3. 确保<uses-library android:name="com.google.android.maps"/> 是Application 的子节点。
  4. 清理/重建我的应用程序。
  5. 已删除 R.
  6. 删除并重建main.xml
  7. 重新启动了 adb 服务器、Eclipse、我的电脑和我的设备。
  8. 在图形布局中在 Android 3.0 和 Android 2.3.3 之间切换。

但是,我的问题仍然存在。这是我的布局 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>

这是我的清单 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>

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

【问题讨论】:

  • 您想要在 MapView 中使用 style="@style/mapView" 还是只是一个错字?
  • @style@styles 抛出相同的错误。到达 /values/style.xml 的正确语法是什么?
  • 你见过这个 SO 问题吗:stackoverflow.com/questions/7371166/…,尤其是最后一个答案。
  • 我做了,但这不是我列出的步骤之一。我会添加它。
  • 感谢您提供信息 :-) 几个小时后,我设法找到了导致此错误的原因 - 这是因为我在 &lt;string&gt; &lt;/string&gt; 中有一个撇号字符。

标签: android eclipse android-layout android-mapview


【解决方案1】:

我的回答可能比较晚,但我希望它能解决实际原因,并确保它对那些将来要搜索相同问题的人有所帮助。

这类错误,

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 

上面列表中的任何东西都可以,

最终的原因是,

我们为layout 选择了不可用的Theme

这可能是因为,

  1. 所选的themethemes.xml 文件中不可用。
  2. 选中的theme属于高版本sdk,但我们当前的目标sdk是低版本。

这个问题大多发生,

  1. 当您复制整个layout 文件并尝试在您的project 中实现它时。 一种。您可能忘记复制themes.xml 文件 湾。你可能有更低的target sdk,原来的layout 用更高的target sdk 创建。

这个问题的解决方案是,

(打开查看Graphical Layout View中的layout文件,并查看右上角。 你的themeslayout 已被选中。)

  1. 所以点击下拉列表theme选择,根据你的项目themestargeted sdk themes选择可用的themes(或)
  2. 如果themecustom 之一,如果您需要它,则将themes.xml 文件从您复制layout xml 文件的源复制到您的项目。 (或)
  3. 如果themesdk可用theme,如果你需要它,然后根据你选择的theme更改你的target

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

【讨论】:

  • 这看起来像是可靠的信息。今天下午我会试着看看。
  • 这并没有解决我的问题。我的主题不是自定义的。如第 2 点和第 8 点所述,我的目标和主题选择是相同的。我正在使用 Theme.NoTitlebar;切换到其他主题并不能解决问题。
  • 这是您的答案stackoverflow.com/questions/8513278/… 的精确副本。此问题与themes.xml 无关,因为主题是从Maps API 继承的。
【解决方案2】:

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

问题如下所示
如果主题不合适,它会给我们缺少样式错误。



这里是解决方案
1.首先选择主题栏。

2.为您的视图选择主题

3.选择主题后,然后按确定。
如果主题适合您的视图,它将呈现,否则请选择另一个主题并尝试直到找到适合您的应用程序的主题。
只要您的主题合适,它就会呈现如下图所示。

【讨论】:

    【解决方案3】:

    我也遇到了类似的问题。

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

    所以我所做的就是删除了该活动并猜猜是什么??它奏效了。

    同样,我不确定这是怎么做到的,但最终对我来说确实如此。

    希望这会有所帮助。

    【讨论】:

      【解决方案4】:

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

      【讨论】:

        【解决方案5】:

        点击刷新按钮

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

        【讨论】:

          猜你喜欢
          • 2011-11-14
          • 2011-10-21
          • 2012-01-20
          • 2012-05-25
          • 2012-03-16
          • 1970-01-01
          • 2016-12-19
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多