Error using "Theme.AppCompat" with Android Studio 2.1.0 - android

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...

Related

I'm receiving this error: Cannot resolve symbol: "#android:style/Widget.Material.Light.Button.TextButton"

I'm a noob - one month learning Kotlin and android studio (Version 3.6.3 on Windows 10). I'm trying to setup a really simple project to experiment with Material Design Widgets using Themes and many kinds of widgets.
I've place the following line at the start of my styles.xml file.
<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light">
I've started by playing with buttons and successfully added one Material design button styled as follows in activity_main.xml:
style="#android:style/Widget.Material.Light.Button"
But when I add a second button styled with:
style="#android:style/Widget.Material.Light.Button.TextButton"
I get the unresolved symbol error.
What am I missing or doing wrong?
Thanks
yes.you skip. instead this
style="#android:style/Widget.Material.Light.Button"
...
style="#android:style/Widget.Material.Light.Button.TextButton"
set this:
style="#style/Widget.MaterialComponents.Button"
style="#style/Widget.MaterialComponents.Button.TextButton"

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 resources in library android

I'm using my own library. In this library I defined some resources:
colors.xml (library)
<color name="colorPrimary">#000000</color>
In my app (that uses the above library). I want to override that color primary.
colors.xml (app)
<color name="colorPrimary">#ffffff</color>
I actually want to override that attribute so that the library (and my app) use the overrided one, not the declared one from library. It works fine but Android Studio keeps yelling out that:
Overriding #color/colorPrimary which is marked as private in my_lib. If deliberate, use tools:override="true", otherwise pick a different name". That makes me think that this is not a good approach.
I also try to add tools:override="true" to the resource:
<resources xmlns:tools="http://schemas.android.com/tools"
tools:override="true">
but the warning still there.
Is there any wrong with what I'm doing?. I can not pick another name because I want the library to use the overrided values.
I'm using Android Studio 2.1.1 and gradle 2.1.0 version.
Thanks.
Move the tools:override to the color tag.
There's nothing wrong with this. Android Studio is just warning you, incase it wasn't deliberate.
If you press alt-enter on the line with the warning, AS will offer to insert the override attribute for you and will put it in the correct place.

Xamarin Colors Causing Build Errors

I have an android application built with Xamarin Studio. I added a file named colors.xml to the Resources/values folder. The contents were:
<resources>
<color name="ViewBackgroundColor">#ffffff</color>
</resources>
To that, I was following this approach to define and use it; however, I was trying to apply it to the view's root element (found that resource elsewhere on SO, don't have exact link). So I applied it to the view by adding android:background="#color/ViewBackgroundColor" attribute to the root element. However, this generates a build error that #color/ViewBackgroundColor isn't a value. is anybody else having this issue and is there a resolution?
To reference that color, you must use all lowercase letters.
So
android:background="#color/viewbackgroundcolor"
This is because the Xamarin tools lowercases all names to be compliant with the rules Android has for resource names.
Is also important to set "Build Action" (with mouse right button on file color.xml) as AndroidResource.

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

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.

Categories

Resources