Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

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

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

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.

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.

However, my problem persists. Here's my layout 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 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...