Android maps:Failed to find style 'mapViewStyle' in current theme - android

I am trying to use maps in my application and i get this error,
Failed to find style 'mapViewStyle' in current theme
i have generated the key properly, and have tried all solutions offered for the same problem at other places.
1.my target api and the one mentioned in the manifest file are the same.
2.There is no import.R in my project
3.I have cleaned my project.
4.Uses-library element is a child of the application.
This is my xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.maps.MapView
android:id="#+id/mapview1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:apiKey="*****************"
android:enabled="true"
/>
</LinearLayout>
and this is my corresponding java file
package com.epidemicator.prototype;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
public class Mapacti extends MapActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
please help me out here...
thanks.

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 occur because of the following reasons,
The selected theme is not available in themes.xml file.
The selected theme is belongs to higher version sdk, but our current target sdk is lower one.
This problem mostly happens,
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.)
So click the dropdown list for theme selection and choose the available themes according to your project themes and targeted sdk themes.
(OR)
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)
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.

I thought I'd add this little tidbit. I was getting error #4 above. It took me forever to realize that the theme I had made for my Preferences was automatically being applied to every single layout file I had already made. Choosing a different one as described above fixed my problem. I don't know why Android Studio automatically applied it to all my other layouts, but I wish it wouldn't.
I still don't know why the theme I'd made was breaking everything, as it was only applying a backgroundColor to my Preferences page, but hopefully someday I will.

Related

Does Android Studio Linter Offer An Option to look for default XML layout values?

1.) Is there any reason to have a default value inside an android xml layout?
Ex.) The TextView below has included a default value of
android:visibility="visible"
`<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:visibility="visible"/>`
Conjecture: Because this is a default value, it has no effect, and therefore is an unnecessary line of code in the XML file. Is that line of thinking correct?
2.) If there is no reason for default values to exist in Android xml files, is there a lint plugin available to point out default value code lines in android XML files?
It is my thought that a large number of code lines in XML files are default values, serving no purpose. What can we do to reduce these lines of code?
U can create a style with your default values and use it.
For example:
<style name="DefaultTextViewStyle">
<item name="android:visibility">visible</item>
</style>
to use this:
<TextView
style="#style/DefaultTextViewStyle" />
I had some hope that the Lint inspection Redundant default value attribute assignment for xml, run via Android Studio might have done what you're asking. You can run it as specified under the Manually Run Inspections part of the Android docs. i.e.Android Studio -> Analyze -> Run Inspection by name -> enter "Redundant default value attribute assignment", then select the scope for the Lint check.
Sadly though, it doesn't pick up the case you mention above. I'm just wondering if there's something I've missed, or if this isn't intended for Android xml in some way?

Override layout xml from android framework

Problem
I want to override a layout file from android namespace, e.g. R.layout.popup_menu_item_layout (which is referenced from code as com.android.internal.R.layout.popup_menu_item_layout). By saying override, I assume declaring an xml file in the project which would be prioritized over the layout that framework owns.
Note, this is just an example layout, so the question concerns to each layout that's present in sdk/platforms/android-XX/data/res/layout directory.
What I've tried
tools:override
There's an undocumented tools:override tag available, which overrides specific resources. See this answer for an example, which overrides values from Design Support Library, not from Android framework.
Applying tools:override="true" to the root tag of the layout won't take effect.
XML layout references - refs.xml
As described in this post, declaring a refs.xml file in /values/ directory with following content:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="layout" name="activity_main">#layout/activity_second</item>
</resources>
will refer to activity_second.xml once activity_main.xml is used. There's an answer that suggests using this technique in order to substitute Snackbar's layout.
This also won't take effect.
Question
Is there any legitimate way to override/substitute a layout file from android package?
I know this is an old question but I also wanted to override a library layout with my own, here's how I did it.
The layout in question was called design_bottom_navigation_item
In refs.xml I added the following:
<resources xmlns:tools="http://schemas.android.com/tools">
<item name="design_bottom_navigation_item" type="layout" tools:override="true">#layout/bottom_navigation_item</item>
</resources>
There are 4 parts to this which I'll explain.
Name: This is the name of the layout you want to override
Type: The type of resource you are trying to override, in this case a layout.
tools:override: This is how you tell Android Studio to override the library layout with your own.
Value: This is where you specify what resource you want to use instead.
You can do this with any resource type this way.
What is that you're trying to do?
If the idea to only replace how the menu-item will look like, you can try the following:
Create a custom MyMenuAdapter extends MenuAdapter
Override the getView method to return the view from your adapter.
You are trying to customise your sdk on the application itself, at runtime.
That's just not how it works.
If you use an SDK on your project(on any technologies), and you need to modify some behavior, you will tweak this SDK and after that, compile your project with this news customized version.
Trying to modify it at runtime is not a good idea.
You will face multiple issues (retro compatibility, security trigger, TREBLE incompatibility , dependency issue, etc)
You have 4 possibilities to do what you want:
Make your own android rom where you will apply your modification
Copy the resources you need to modify on a fake xmlObject with the tag, after the onPostCreate of your application, you will be able to modify the when inflation. You can generalize this behavior and it will simulate an sdk overlay.
Make your own sdk :)
Multi-level reflection, but, no way you succeed with a stable version
Of course, none of this solutions is applicable for a public app.
don't know your issue have fixed or not but simple solution for this is create new layout that is same layout name of framework (in this case is popup_menu_item_layout). Then go to android google source to copy xml content popup_menu_item_layout
So you can custom anything u want. But remember don't change any id of views.

Error using "Theme.AppCompat" with Android Studio 2.1.0

In my android project, I am getting the error "Cannot find symbol for Theme.AppCompat" while using it in styles.xml file:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
I have included the app compat dependency in my gradle file:
'compile 'com.android.support:appcompat-v7:23.3.0'
I tried finding the solution all over internet but nothing helps. Can someone help me with this..
Just wanted to let you know that you're not alone. Everything was working fine in the app I was developing, testing heavily on a marshmallow nexus 5 and a lollipop samsung tablet. I must have let something automatically update, because now I'm having problems with appcompat.
Here's an example of what's going wrong:
in a layout XML I have an edit text with style specified:
style="#style/Widget.AppCompat.EditText"
This will cause 'Error inflating class EditText'
if I create a style for the edit text in v21 styles with a parent of 'Widget.AppCompat.EditText' and specify the background (my color, or drawable, or ?android:attr/editTextStyle) it will work - though all of these options lose the edittext underline style.
If I specify background of ?attr/editTextStyle it will fail to inflate, which I assume is the default, it will fail to inflate. Likewise, if I leave any style tag off of the edit text, it will also fail to inflate.
Glad I'm not alone, but I wish this wasn't a thing...

finding resources of view

I'm trying to add to my project the source code of SlidingDrawer, I could find it easily in grepCode.
The problem is that the code is not compiling, there's references to native resources, for Ex.
R.styleable.SlidingDrawer_orientation
that I'm cannot find, neither in GrepCode nor in Android repositories at GitHub.
does anyone have encountered in such a scenario and was managed to solved it?
Thanks.
So I just tried doing this, I had compile errors related to the resources as well. Those resources are not publically available to android.R. As the previous answerwer said, some resources are declared internal/hidden.
Once I imported my own frameworks_all.jar file I was able to see them and even build my own little SlidingDrawer class, with no more work than just copying the file into my own project.
This is an excellent guide to get you started on understanding the concepts of / getting used to using Android's hidden and internal classes:
Amazing Super Awesome Guide to Android's Internal / Hidden API which will totally work and make your life better
Note The attributes appear to be hidden, not internal, so you just need to worry about getting access to hidden components.
A bit of background if you are interested though, the resource file for android (android.R) gets compiled specially in frameworks/base. The attribute you want doesn't appear to exist on it's own, I.E. there is no xml file in frameworks base where R.styleable.SlidingDrawer_orientation exists. That's why you couldn't just find it. There IS however, an attribute file: frameworks/base/core/res/res/values/attrs.xml which you can find the orientation listed as an attribute for:
<!-- SlidingDrawer specific attributes. These attributes are used to configure
a SlidingDrawer from XML. -->
<declare-styleable name="SlidingDrawer">
<!-- Identifier for the child that represents the drawer's handle. -->
<attr name="handle" format="reference" />
<!-- Identifier for the child that represents the drawer's content. -->
<attr name="content" format="reference" />
<!-- Orientation of the SlidingDrawer. -->
<attr name="orientation" />
...
Seems like android marks all the styleable attributes hidden because the entire section is obscured from public code. I'm not sure of the specifics in how this R file gets constructed, I'd have to dig more into make files to find out. Either way, end fluff, to reiterate all you need to do is get access to the internal/hidden components.
The R file is auto generated based on the resource files you have under the folder /res
Read more about it: http://developer.android.com/guide/topics/resources/providing-resources.html
So in this case, you don't have a resource defined for SlidingDrawer_orientation...try to look for the corresponding resource under the /res folder from the project you are copying from. Some resources from the Android OS library are declared internal/private...therefore you can't really access them in your code, what you could do is replicate if you have the proper resources.

Custom state drawables not working in Library Projects

Any searches for any information on how to provide your own custom state for use in a drawable state list selector pulls up very little but almost all of them (here and elsewhere) refer to this google groups post.
I have getters and setters like this: (Not included in the above post, but using their wording to keep it simple)
public void setFried(boolean fried){
if(mFried != fried){
mFried = fried;
refreshDrawableState();
}
}
public void isFried(){
return mFried;
}
I have been trying to get it to work for the last couple hours and nothing seems to be working. It just simply does not change the appearance. I watched what happened as it called onCreateDrawableState(), and I watched what would come out of getDrawableState() after I changed the custom state. The custom state values are in fact appearing in the drawableState array.
Since I can see the state is actually being merged into the array, and since it seems to be completely ignoring any of my custom state in the selector, I think the xml must be wrong.
Here is what the post suggested:
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/my.app.package">
<item android:drawable="#drawable/item_baked" state_baked="true"
state_fried="false" />
<item android:drawable="#drawable/item_fried" state_baked="false"
state_fried="true" />
<item android:drawable="#drawable/item_overcooked" state_baked="true"
state_fried="true" />
<item android:drawable="#drawable/item_raw" state_baked="false"
state_fried="false" />
</selector>
Can you really just write state_fried and state_baked or do they need a prefix like app:state_fried? If I try adding a prefix I get a Console error like: No resource identifier found for attribute 'state_fried' in package my.app.package
Has anyone actually got custom states to work? Is the referenced post all you need to get this to work or is there something wrong with it or missing?
I don't know if it makes any difference but I am using an Android Library Project and the selector and the attr.xml is in the Library project.
Thanks
Update
Looks like the problem is that Library Projects don't play well with custom attributes. See here, here, here.
Haven't seen much of a workaround unfortunately...
I wrote that original question. IIRC, that was when Android was in beta, and things have changed a bit. Custom attributes do indeed work; I use them. You do indeed need the app: prefix for custom state attributes. You also need to substitute your app's package in place of my.app.package in the xmlns declaration.
use
xmlns:app="http://schemas.android.com/apk/lib/my.app.package
for attributes declared in the library.

Categories

Resources