Android - Error inflating SimonVT NumberPicker class in my layout xml - android

I've been at this for days now, and I am at the point of giving up, so any help is much appreciated!
I've been trying to implement the simonVT numberpicker in my android app. Completely new to android, so including the library, referencing this library and getting everything to compile has been a few days mission in itself. Now I finally have everything compiling I get the following error at runtime:
04-06 10:58:37.126: E/AndroidRuntime(14324): java.lang.RuntimeException:
Unable to start activity ComponentInfo{com.example.goalminder/com.example.goalminder.AddGoal}:
android.view.InflateException: Binary XML file line #81:
Error inflating class net.simonvt.numberpicker.NumberPicker
Here is the opening of my layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/net.simonvt.numberpicker"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
NB - The 'xmlns:app' part above has a yellow warning marker - it's not being used. I included this per another stackoverflow answer re. a similar problem. Have left in to discourage this suggestion.
Here is the xml for the numberpicker:
<net.simonvt.numberpicker.NumberPicker
android:id="#+id/dayPicker"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginRight="10dp"
android:layout_weight="1"/>
I have included the theme as instructed by Simon in my theme file. I wasn't really sure what name to give it, so I called it 'NumberPicker':
<resources>
<!-- Copy one of these attributes to your own theme (choose either dark or light).
<item name="numberPickerStyle">#style/NPWidget.Holo.NumberPicker</item>
<item name="numberPickerStyle">#style/NPWidget.Holo.Light.NumberPicker</item>
-->
<style name="NumberPicker" parent="android:Theme">
<item name="numberPickerStyle">#style/NPWidget.Holo.NumberPicker</item>
</style>
<style name="NumberPicker" parent="android:Theme.Light">
<item name="numberPickerStyle">#style/NPWidget.Holo.Light.NumberPicker</item>
</style>
</resources>
I have also added the following to my android manifest as a child of application:
<activity
android:name="net.simonvt.numberpicker.Numberpicker" />
<activity
android:name="net.simonvt.numberpicker.Scroller" />
I've been all over stackoverflow, so what we have above is a scatter gun approach of everything I have seen recommended so. As stated before, I'm floundering with this and am close to implementing a standard ugly list.
NB - I got all this working with the native android implementation of Numberpicker. I want to use Simon VT's backport version however as I will be looking to support API < 11, which includes Gingerbread which I believe has a 39.7% distribution. Please let me know if you think I don't need to support this far back.

you need add theme for the activity on AndroidManifest.xml:
Example:
<activity android:name="yourActivity" android:theme="#style/SampleTheme.Light"/>

If you don't want to create a theme for your own project, you may do the following to the source code of numberpicker to set it to use the default theme NPWidget_Holo_numberPicker.
Replace the constructor with the following
public NumberPicker(Context context, AttributeSet attrs) {
this(context, attrs, R.style.NPWidget_Holo_NumberPicker);
}
then change the assignment of TypedArray attributesArray to the following:
TypedArray attributesArray = context.obtainStyledAttributes(
attrs, R.styleable.NumberPicker, 0, defStyle);

See Simon's usage notes:
Requires adding a single attribute to your theme. Check the sample app for how this is done.
values/theme.xml:
<style name="SampleTheme" parent="android:Theme">
<item name="numberPickerStyle">#style/NPWidget.Holo.NumberPicker</item>
</style>
values-v11/themes.xml:
<style name="SampleTheme" parent="android:Theme.Holo">
<item name="numberPickerStyle">#style/NPWidget.Holo.NumberPicker</item>
</style>

Try replacing net.simonvt.numberpicker.NumberPicker with com.your.package.NumberPicker.

I was having practically the same problem, I was getting the error
11-18 21:13:18.627: W/ResourceType(13799): No package identifier when getting value for resource number 0x00000000
I finally realised that I had to add the style item into my own style definitions (as Paul Lammertsma shows above) as I was just copy/pasting SimonVT's styles, which of course my application wasn't using:
<style parent="#android:style/Theme.Holo.NoActionBar.Fullscreen" name="NoActionBar">
<item name="numberPickerStyle">#style/NPWidget.Holo.NumberPicker</item>
</style>
Then, after it still not working, I found I'd completely missed a themes.xml file (I have three for different API levels).

Related

Custom views and defStyleAttr

I'm struggling with custom views defStyleAttr. (Short note I'm using a Preference as example cause it's the same way Google uses it)
So for almost every View or Preference that is provided by Android you'll have a constructor like this:
public SeekBarPreference(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.seekBarPreferenceStyle);
}
This defines the default style attribute to be R.attr.seekBarPreferenceStyle.
If you now look into the definition you'll find this:
<attr name="seekBarPreferenceStyle" format="reference" />
Until now everything is clear. But this attribute is somehow linked to a theme:
<resources>
<style name="PreferenceThemeOverlay">
<!-- ... -->
<item name="seekBarPreferenceStyle">#style/Preference.SeekBarPreference.Material</item>
<!-- ... -->
</style>
<!-- ... -->
</resources>
Which then finally links a style with the needed layout resource id that will be handed over to the super class to be inflated:
<style name="Preference.SeekBarPreference.Material">
<item name="android:layout">#layout/preference_widget_seekbar_material</item>
<!-- ... -->
</style>
Unfortunately I wasn't able to find a hint on how the theme PreferenceThemeOverlay is linked to the attribute seekBarPreferenceStyle.
So how are these two linked?
I finally found an answer that explained the basics you need to know.
Custom View
For the examples I use SeekBarPreference as a custom object (Preference and View are very similar)
So in short there are two ways to set your default style.
Either set a custom theme to your activity (or the like) that links something to your custom style (seekBarPreferenceStyle) or set the style directly by the style XML attribute.
Theme
styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="seekBarPreferenceStyle">#style/LINK_TO_DEFINING_STYLE</item>
</style>
AndroidManifest.xml
<activity android:name=".SomeActivity" android:theme="#style/AppTheme">
Style attribute
some.xml
<SeekBarPreference
[...]
style="#style/LINK_TO_DEFINING_STYLE"
[...] />
Androids Way
But I wanted to know exactly how all of it is connected to then work without any style attributes in XML files for SeekBarPreference or other Preference and View objects provided by Android.
So (via Android Studio) I followed Theme.AppCompat.Light.DarkActionBar down to its parent Theme.Holo.Light and look what I found there:
<!-- ... -->
<item name="seekBarPreferenceStyle">#style/Preference.Holo.SeekBarPreference</item>
<!-- ... -->
Linking to this style which links the layout resource:
<style name="Preference.Holo.SeekBarPreference">
<item name="layout">#layout/preference_widget_seekbar</item>
</style>
And to finally bring some more confusion to you again, Android seems to link a the Material style from the question instead of the Holo theme from the answer to the default theme (be it DeviceDefault or something else).
So if you got any clue on this please feel free to add to the comments :)

Meaning of 'android:' prefix within attribute value (e.g. "android:imageButtonStyle")

I want to style all my ImageButtons in a theme. After searching for quite some time I found the solution to my problem. But I don't know why it works like it does.
My main layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<ImageButton
android:id="#+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#mipmap/ic_launcher_foreground" />
</LinearLayout>
This is my original theme that didn't work. It styles my TextView but ignores the ImageButton. The result is shown in the screenshot below.
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:imageButtonStyle">#style/redBackground</item>
<item name="android:textViewStyle">#style/redBackground</item>
</style>
<style name="redBackground">
<item name="android:background">#FF0000</item>
</style>
</resources>
And here's the theme that works:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="imageButtonStyle">#style/redBackground</item>
<item name="android:textViewStyle">#style/redBackground</item>
</style>
<style name="redBackground">
<item name="android:background">#FF0000</item>
</style>
</resources>
The only difference is the missing 'android:' prefix in front of the 'imageButtonStyle' attribute.
So my questions are:
What is the difference between imageButtonStyle and android:imageButtonStyle?
Why does android:textViewStyle work but not android:imageButtonStyle? They are both defined the plattforms 'attrs.xml'.
Why is there no textViewStyle (without android prefix)? Removing the prefix yields an error.
Where are the attributes defined that have no prefix? Apparently not in the plattforms 'attrs.xml'.
Where can I find proper documentation for the whole style stuff? Of course I halve already read the respective Google docs (https://developer.android.com/guide/topics/ui/look-and-feel/themes.html). But still i have basic questions like this one.
Interestingly, it seems like the 'android:imageButtonStyle' version has worked some years ago: How to apply an style to all ImageButtons in Android?. I haven't tested that myself, though.
And here's the post that proposed removing the android prefix. Including unanswered comments that ask why it works: buttonStyle not working for 22.1.1
android tag that you use is used for attribute coming from Android SDK.
app tag is used if you are using the support library.app is just a namespace for any custom parameters for a custom View.
This can be anything but if you see the root element there's probably a line xmlns:app="http://schemas.android.com/apk/res-auto" that assigns the namespace
You may also see other namespaces if you are using custom views (of your own or form a library).
In case that anyone else stumbles across the question: I've found the answer in this Droidcon talk: https://youtu.be/Jr8hJdVGHAk?t=21m12s
The topic is handled in a minute starting at 21:12.
As I understand it, specifying no namespace results in the global namespace being searched which seems to include the support libraries attributes. And indeed both, the SDK's R.attr as well as the support library's R.attr define the imageButtonStyle attribute (with slightly different descriptions). However, the support library does not define a textViewStyle attribute. So that explains why you can't omit it's android: prefix.
To answer my last question concerning the documentation: Despite the Google guide and the R.attr classes' documentation, the video mentioned above and this Google I/O talk are quite informative: https://www.youtube.com/watch?v=TIHXGwRTMWI
So the only question that is left open is why the SDK's imageButtonStyle does not work.

Android XML: RuntimeException: Failed to resolve attribute at index 6

Hello dear stackoverflower,
In my project, i am using the new "android design library".
The problem is, that there is a runtime exception which says(Im trying to create a FloatingButton):
java.lang.RuntimeException: Failed to resolve attribute at index 6
at android.content.res.TypedArray.getColorStateList(TypedArray.java:426)
at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:91)
at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:79)
at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:75)
I was able to figure out, which the attribute cannot be resolved :
<style name="Widget.Design.FloatingActionButton" parent="android:Widget">
<item name="android:background">#drawable/fab_background</item>
<item name="backgroundTint">?attr/colorAccent</item> **!! this one is missing !!**
<item name="fabSize">normal</item>
<item name="elevation">#dimen/fab_elevation</item>
<item name="pressedTranslationZ">#dimen/fab_translation_z_pressed</item>
<item name="rippleColor">?attr/colorControlHighlight</item>
<item name="borderWidth">#dimen/fab_border_width</item>
</style>
This is located in res/values/styles/styles.xml in the android-design-library
i have read in this post that the API lvl should bis 21+. But as the design library supports API 7+, this should not be a problem actually.
It is also worth to mention that i have not included the design library as a gradle-dependency like this:
compile 'com.android.support:design:22.2.0'
I am adding the library manually to the project because the Jenkins server has no Internet access.
I have updated the support-v4 library to 21.2.0
also the appcompat support-v7 is included and updated.
Here is the android-design-library gradle file:
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 17
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
It would be great if someone can help me.
Ran into this problem myself. It's because my app isn't using AppCompat yet, still just the regular support FragmentActivity. This means that FloatingActionButton was looking for two theme attributes and it couldn't find them.
Specifically adding in these missing attributes made it work for me without the need to start using AppCompat.
<LinearLayout
...
xmlns:app="http://schemas.android.com/apk/res-auto"
.../>
<android.support.design.widget.FloatingActionButton
...
app:backgroundTint="#color/{some color statelist}"
app:rippleColor="#color/{some color statelist}"
... />
</LinearLayout>
Had the same issue because have used getApplicationContext() instead of Activity to retrieve LayoutInflater and inflate item view for list adapter.
You can solved this problem by using Theme.AppCompat.Light as your activity's parent theme.
add:
The reason is that one of the default style using inner in FloatingActionButton is declare like this:
the backgroundTint is refer to another attribute colorAccent which should be measure declared in our theme, otherwise, the exception might be throw.
But colorAccent is declared in AppCompat Theme and did not declared in the sdk default Theme.To measure that we can using the design lib correctly in running, one of the easy way is to measure the using of AppCompat Theme like Theme.AppCompat.Light.
I was using a custom attribute in attrs.xml and a customview. I ran into this problem as I didn't specify theme: attribute in the custom view. Quick look of how the files look
attrs.xml
<resources>
<attr name="textColorPrimary" format="reference" />
...
</resources>
customview.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tvText"
style="#style/TitleBlackThin"
android:theme="#style/AppTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:padding="16dp"
android:text="#string/text" />
In my styles.xml, I extended my style to use AppTheme
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="textColorPrimary">#color/black</item>
</style>
...
<style name="TitleBlackThin">
<item name="android:textSize">20sp</item>
<item name="android:fontFamily">sans-serif-light</item>
<item name="android:textStyle">normal</item>
<item name="android:textColor">?textColorPrimary</item>
</style>
...
</resources>
The culprit here was custom attribute ?textColorPrimary. As I didn't define AppTheme in the customview, it wasn't able to determine how to load textColorPrimary. By android:theme="#style/AppTheme", this got fixed))
Make sure your theme .
My theme :
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#2196F3</item>
<item name="colorPrimaryDark">#1565C0</item>
<item name="colorAccent">#E91E63</item>
</style>
This is because of more than one style.xml files.
Add below line in your app build.gradle file:
compile 'com.android.support:design:22.2.0'
I came across this problem as I create my custom view with a custom attribute, but using applicationContext. I think that the application context misses my attribute's information. Changing to the activity's context fixed my problem here.
In my case, I had an error at setContentView(R.layout.my_layout).
In my_layout, I was using app:errorEnabled="true" in a TextInputLayout which caused the error. Removed that line, and it worked.
I was getting this exception while running tests against a fragment that had a custom view. To fix it, I needed to set a theme when launching the fragment.
launchFragmentInContainer<FulfillmentFragment>(
fragmentArgs = bundleOf(
"foo" to "7",
"bar" to "7"
),
themeResId = R.style.Theme_FooBar
)
https://developer.android.com/reference/kotlin/androidx/fragment/app/testing/package-summary#launchFragmentInContainer(android.os.Bundle,kotlin.Int,androidx.lifecycle.Lifecycle.State,androidx.fragment.app.FragmentFactory)
For my case, this issue started showing up after migrating to AndroidX. The scenario was I implemented custom views that extends AppCompatEditText and set custom styles as well. I ran into this issue while running the unit tests.
The error logs show this as the root cause:
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 13: TypedValue{t=0x2/d=0x7f0300f9 a=2}
at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:946)
at android.content.res.TypedArray.getDrawable(TypedArray.java:930)
In the styles I was using Base.Widget.AppCompat.EditText:
<style name="MyEditText" parent="Base.Widget.AppCompat.EditText">
<item name="android:fontFamily">...</item>
<item name="android:textSize">...</item>
</style>
Changing the parent to Android's base android:Widget.EditText removed the error and didn't change any behavior/UI for me.
It's strange since digging through the inheritance structure of Base.Widget.AppCompat.EditText, the root parent is also android:Widget.EditText.
In case anybody comes across this while setting up Android TV / working alongside the AndroidTV sample code, then the solution is to add the leanback theme to your activities in the manifest
<activity
android:name=".PlaybackActivity"
android:theme="#style/Theme.Leanback" />
For some people the problem may be lying under AppCompat/Material theming. To use some material widgets you have to migrate your app theme to it.

Why is my Button text forced to ALL CAPS on Lollipop?

In my app "Tide Now WA" which I recently tested for compatibility using
the new Nexus 9 tablet (Lollipop - API 21).
It writes some button text. This app writes the text correctly using Android 2.3 and Android
4.0. I.e. mixed capital and lower case letters.
When same app is run on my Nexus 9 all the letters
in the text are capitalized.
FWIW my manifest contains the following statement:
uses-sdk android:minSdkVersion="10" android:targetSdkVersion="14"
Can I fix this in my code or is it a bug in the O.S.
thanks
I don't have idea why it is happening but there 3 trivial attempts to make:
Use android:textAllCaps="false" in your layout-v21
Programmatically change the transformation method of the button. mButton.setTransformationMethod(null);
Check your style for Allcaps
Note: public void setAllCaps(boolean allCaps), android:textAllCaps are available from API version 14.
Here's what I did in my values/themes.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="buttonStyle">#style/MyButton</item>
</style>
<style name="MyButton" parent="Widget.AppCompat.Button">
<item name="android:textAllCaps">false</item>
</style>
This is fixable in the application code by setting the button's TransformationMethod, e.g.
mButton.setTransformationMethod(null);
Set android:textAllCaps="false". If you are using an appcompat style, make sure textAllCaps comes before the style. Otherwise the style will override it. For example:
android:textAllCaps="false"
style="#style/Base.TextAppearance.AppCompat"
add this line in style
<item name="android:textAllCaps">false</item>
this one is working .... just in your code in your bottom code add this one :
android:textAllCaps="false"
it should deactivate the caps letter that U trying to type small .
Lollipop default comes with "textAllCaps true", so you have to manually make it to false
Use this line android:textAllCaps="false" in your xml
<Button
android:id="#+id/btn_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/login_str"
android:background="#color/colorBlue"
android:textColor="#color/colorWhite"
android:textAllCaps="false"
/>
Add android:textAllCaps="false" in <Button> tag that's it.
There is an easier way which works for all buttons, just change appearance of buttons in your theme, try this:
in values-21/styles.xml
<resources>
<style name="myBaseTheme"
parent="#android:style/Theme.Material.Light">
<item name="android:colorPrimary">#color/bg</item>
<item name="android:colorPrimaryDark">#color/bg_p</item>
<item name="android:textAppearanceButton">#style/textAppearanceButton</item>
</style>
<style name="textAppearanceButton" parent="#android:style/TextAppearance.Material.Widget.Button">
<item name="android:textAllCaps">false</item>
</style>
</resources>
PS: it's recommended to follow material design's principles, you should show capitalized text in Buttons, http://www.google.com/design/spec/components/buttons.html
Java:
yourButton.setAllCaps(false);
Kotlin:
yourButton.isAllCaps = false
XML:
android:textAllCaps="false"
Styles:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="buttonStyle">#style/yourButtonStyle</item>
</style>
<style name="yourButtonStyle" parent="Widget.AppCompat.Button">
<item name="android:textAllCaps">false</item>
</style>
In layout:
<Button
.
.
style="#style/yourButtonStyle"
.
.
/>
You could add android:textAllCaps="false" to the button.
The button text might be transformed to uppercase by your app's theme that applies to all buttons. Check themes / styles files for setting the attribute android:textAllCaps.
Using the android.support.v7.widget.AppCompatButton in the XML layout will allow you to avoid having to have a layout-21 or programmatically changing anything. Naturally this will also work with AppCompat v7 library.
<android.support.v7.widget.AppCompatButton
android:id="#+id/btnOpenMainDemo"
android:textAllCaps="false"
style="#style/HGButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btn_main_demo"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
Hope this helps.
In Android Studio IDE, you have to click the Filter icon to show expert properties. Then you will see the textAllCaps property. Check it, then uncheck it.
If you have arrived here because your facebook button text appears in all caps then just add this android:textAllCaps="false" in your xml file. It worked for me.
OK, just ran into this. Buttons in Lollipop come out all uppercase AND the font resets to 'normal'. But in my case (Android 5.02) it was working in one layout correctly, but not another!? Changing APIs didn't work. Setting to all caps requires min API 14 and the font still resets to 'normal'. It's because the Android Material Styles forces a change to the styles if there isn't one defined (that's why it worked in one of my layout and not the other because I defined a style). So the easy fix is to define a style in the manifest for each activity which in my case was just: android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
(hope this helps someone, would have saved me a couple of hours last night)
If you use appcompat-v7, you can subclass AppCompatButtonand setSupportAllCaps(false), then use this class for all your buttons.
/**
* Light extension of {#link AppCompatButton} that overrides ALL CAPS transformation
*/
public class Button extends AppCompatButton {
public Button(Context context, AttributeSet attrs) {
super(context, attrs);
setSupportAllCaps(false);
}
public Button(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setSupportAllCaps(false);
}
}
See AppCompatButton#setSupportAllCaps(boolean) Android docs.
By default, Button in android provides all caps keyword. If you want button text to be in lower case or mixed case you can disable textAllCaps flag using android:textAllCaps="false"
I do not know why the answer of #user1010160 got rating of 0. I would have given it +1 if I had enough reputations.
Since my app is designed for API less than 14 and I did not want to add code to my program I did not find a solution until I read his answer. What he said was that even though you have done what is needed in the Application styles it will not work unless you add a style to your activity and there you set textAllCaps to false.
It is not enough to have a style for the activity (my activity had a style), because the style might defaults to the AllCaps property. You have to set explicitly, in the activity too, that property to false.
I now have it both in the Application and in the Activity parts of the manifest file.
Another programmatic Kotlin Alternative:
mButton.transformationMethod = null

Missing styles. Is the correct theme chosen for this layout?

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.
I tried every solutions available to solve this problem but nothing seems to work. I have included library in the manifest file. I even created style is styles.xml, I have chosen Google Apis build target as well.
Can somebody please give me a solution?
here is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="#style/AppTheme"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.maps.MapView
android:id="#+id/themap"
style="#style/mapViewStyle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="here i have my key"
android:clickable="true"
android:enabled="true" />
</RelativeLayout>
Here is my manifest snippet:
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Second" />
<activity android:name=".Third" android:theme="#android:style/Theme.Black"/>
</application>
here is my style.xml file
<resources>
<style name="mapViewStyle" parent="#android:style/Theme.Black">
</style>
</resources>
For Android Studio (or IntelliJ IDEA),
If everything looks OK in your project and you're still receiving the error in your layouts, try to 'Invalidate caches & restart'.
Enjoy a coffee while Android Studio is recreating caches & indexes.
I had the same problem and found it was the Theme dropdown at the top of the graphical layout editor. I changed from Holo to Theme and the layout displayed and error disappeared.
What I usually do is the following: a Gradle Clean, Rebuild and Sync all my Gradle files. After that I restart Android Studio, and I go to:
Select Theme -> Project Themes -> AppTheme
This is because you select not a theme of your project. Try to do next:
If we are creating too many projects using Android Studio sometime Rendering issue comes. Even creating a blank activity we receive such rendering error.
Please shut down and restart Android studio. In case the issue persists you can
Hope this helps. It works similar fashion as rule of thumb, in case all looks good and still error persists a restart of application usually resolves the issue.
In my case the problem occurred while the default setting for Android Version in the Designer was set to 'Preview N'. Changed Android Version to '23' and the error notification went away.
Edit And don't forget to uncheck 'Automatically Pick Best'.
I had the same problem using Android Studio 1.5.1.
This was solved by using the Android SDK Manager and updating Android Support Library, as well as Local Maven repository for Support Libraries.
After updating the SDK and restarting Android Studio, the problem was rectified.
Hope this helps anyone who has the same problem after trying other suggestions.
I solved it by changing "classpath" in "dependencies" in build.gradles.
Just change:
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0-alpha2'
or something like that to:
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
I got this error after overriding action bar style like this. Also i lost action bar in preview.
<style name="general_app_theme" parent="#style/Theme.AppCompat">
<!-- for API level 11 -->
<item name="android:actionBarStyle">#style/action_bar_style</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/action_bar_style</item>
</style>
<style name="action_bar_style" parent="#style/Widget.AppCompat.ActionBar">
<!-- for API level 11 -->
<item name="android:height">#dimen/action_bar_height</item>
<item name="android:background">#color/action_bar_color</item>
<item name="android:displayOptions">showTitle</item>
<!-- Support library compatibility -->
<item name="displayOptions">showTitle</item>
</style>
So, problem is overriding theme by my custom. this is the reason, why I've changed AppCompat (from "Project Themes") to general_app_theme (from "Manifest Themes"). Now I have no this error and action bar in preview come back.
Try switching the theme in the design view to one of the options in "Manifest Themes". I'm guessing this is Because you are inheriting the theme from the manifest to support multiple api levels. It worked for me anyway.
With reference to the answer provided by #Benno:
Instead of changing to a specific theme, you can simply choose 'DeviceDefault' from the theme menu. This should choose the theme most compatible with the emulated device.
If you still have the problem after trying all the solutions aboveļ¼Œ please try modify the API Level as shown below. Incorrect API Level may also cause the problem.
It can be fixed by changing your theme in styles.xml from
Theme.AppCompat.Light.DarkActionBar to Base.Theme.AppCompat.Light.DarkActionBar
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
to
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
and clean the project. It will surely help.
Most of the errors in XML happen due to the names you have given to the resources.
Images stored in the drawable folder need to be named in a proper manner.
just check these things:
Are there any duplicate files? if so remove the duplicates. (For example "image.jpg" and "image.png" are not allowed in the same time. It will not show any errors but sometimes it will show that R.java cannot be resolved)
Do the filenames contains any uppercase letters? If so right click on that file->refactor->rename
and rename it with all lowercase, no hyphens, and only a-z and 0-9 are allowed.
Just make sure of the above cases.
I got the same problem with my customized theme that used Holo.Light as its parent. In grayed text Android Studio indicated that some attributes were missing. When I added these missing attributes as follows, the rendering problems went away -
<item name="android:textEditSuggestionItemLayout"></item>
<item name="android:textEditSuggestionContainerLayout"></item>
<item name="android:textEditSuggestionHighlightStyle"></item>
Even though they introduced errors in my style's theme, they caused no problems in rendering the activity designs or building my app.
You can simply remove this error through change "App theme" and select any theme such as light. This error will be removed.
I meet the same problem.Select theme to another one in preview can solve problem temporary.Like the image
Finally,I found out that there are AppTheme and AppBaseTheme in my styles.xml.
And AppTheme has parent AppBaseTheme.
The AppBaseTheme has parent of one system style.
And every layout file use the theme AppTheme.
Just change AppTheme's parent to AppBaseTheme's parent.
It solve the problem permanent.
Just need click button 'AppTheme', and choose 'Manifest Themes'. It works in most cases.
For me, it was occurring on menu.xml file as i was using android:Theme.Light as my theme, So what i did was -
Added new Folder in res directory named values-v21.
Added android:Theme.Material.Light as AppTheme in styles.xml.
This is very late but i like to share my experience this same issue.
i face the same issue in Android studio i tried to some other solution that i found in internet but nothing works for me unless i REBUILD THE PROJECT and it solve my issue.
Hope this will works for you too.
Happy coding.
Change your App theme to AppCombat..

Categories

Resources