I can not sync my gradle project. Every time I sync, it shows an error:
Error:(11) Tag <style> can not appear inside <style>, only <item>
When I edit value.xml & value-v21.xml or remove <style> , it will reappear.
How to solve the problem?
build gradle app:
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "ir.bijac.com.bijac"
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
And dependencies:
compile 'com.android.support:appcompat-v7:28.0.0'
compile 'com.android.support:design:28.0.0'
Try deleting the value-v21.xml and if tag is still nested in value.xml , edit it.
Hope this helps
Put MyCheckbox style to outside of AppTheme.NoActionBar
The error is very clear you can't do this
<stle><style> </style></style>
instead what you can do is
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme">
<item name="android:textViewStyle">#style/MyTextViewStyle</item>
</style>
<style name="MyTextViewStyle" parent="android:Widget.TextView">
<item name="android:textColor">#F00</item>
<item name="android:textStyle">bold</item>
</style>
</resources>
Hope this will help you
Remove the MyCheckBox style from inside of AppTheme.NoActionBar style.
Tag <style> can not appear inside <style>, only <item>
It's says that a style can not contain another style inside, just an item, so removing MyCheckBox style outside it should work.
Make sure your layout.xml only contains one style inside a component, for instance :
<Checkbox>
...
...
style=#style/MyCheckBox
</Checkbox>
Oh, I see you can edit so, please try first :
File/Invalidate Caches/Restart
if it does not work, make sure you can scroll up and down in your styles, then you can edit it.
Also make sure you are not editing the files that Android studio are generating automatically make sure you are editing this :
app->src->main->res->values
Related
I have recentely started learning android studio and I know nothing about the errors.
I am dropping the text and buttons to the design view but I am unable to see them.
[]
Here are a few errors that are apperaring at the top right corner.
[]
The errors say:
Failed to find style coordinatorLayoutStyle in current theme.
This view is not constrained. It only has designtime positions, so it will jump to (0,0) at runtime unless you add the constraints.
Missing styles. Is the correct theme chosen for this layout?
Some fixes that i have tried after googling are:
In styles.xml changing
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
[]
Also i found that i should change:
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
to
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
But in place of alpha3 there is rc01
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
[]
Nothing worked for me, please need a detailed answer as I am new to android studio.
remove this from gradel
implementation 'com.android.support:appcompat-v7:28.0.0- alpha3
and add this
implementation 'com.android.support:appcompatv7:27.0.1'
implementation 'com.android.support:design:27.0.1'
like this
android {
compileSdkVersion 27
defaultConfig {
applicationId "e.lenovo.alldemo"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
I know this question has been asked a lot of times but I have tried most of the solutions, and none worked for me.
This is the first time that I'm working on android studio 3.1.3, and I was following a tutorial on how to create a simple app using the basic template option from the android studio. The problem that I'm facing is;
Render Problem Failed to find style 'coordinatorLayoutStyle' in
current theme
I have tried adding this to the build.gradle file:
compile 'com.android.support:design:24.1.1'
Also this into the style.xml
<style name="AppTheme.NoActionBar">
<item name="coordinatorLayoutStyle">#style/Widget.Design.CoordinatorLayout</item>
</style>
styles.xml
<resources>
<!-- Base application theme. -->
<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>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
Couldn't resolve resource #style/Widget.Design.CoordinatorLayout<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
build.gradle
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.notes"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:28.0.0-alpha3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
I was having the same problem. I tried following steps from here, but still the problem persists. I think it is a common issue in android studio 3.0+, Hopefully they will fix it next update. In the Android Studio Preview 3.2 it works fine. Download Android Studio Preview and visit here to learn how to run it alongside with Android Studio stable version
Or you can try to lower your design library version to 27. (And the compile sdk version also to 27)
dependencies { implementation 'com.android.support:appcompat-v7:27.0.2' implementation 'com.android.support:design:27.0.2' }
Try adding "Base" before Theme in styles.xml as show : - "Base.Theme.AppCompat.Light.DarkActionBar"
Permanent solution for this problem: change your build gradle (module app) to implementation com.android.support:appcompat-v7:28.0.0-alpha1.
change your build gradle (module app)
from : com.android.support:appcompat-v7:28.1.1-alpha3
to : com.android.support:appcompat-v7:27.1.1
1.try this first : make changes in Gradle (module app) for appcompat:
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
2. If it doesn't work clean your project and then again build it.
In my case, it worked.
I am developing an app with minSdkVersion 11, targetSdkVersion 23 and compile/build tool version 23. On android versions, 5 and 6 my app works fine, but installing the app on versions below 22 modifies some layouts, like buttons and text fields disappear or color changes, help me with this.
Manifest File
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.khan.bilal.salamrides2">
<application
android:allowBackup="true"
android:icon="#mipmap/cc"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
Styles file
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowNoTitle">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.AppBarOverlay"
parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay"
parent="ThemeOverlay.AppCompat.Light" />
</resources>
Build Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.khan.bilal.salamrides2"
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
}
Screen Shot of android version 22(Works fine)
Screen Shot of android version below 22(problem occurs)
When you use an element that was introduced in API 21, and you try to show it on a phone with API 11, there surely will be a problem. For the older versions, you have to differentiate between the elements that you are showing - if some element is not meant to be used in API lower than 21, then you have to provide if-else check and if the API is lower than 21, then use some simple element that you are sure was supported even in API 11.
For example, if you want to use TextInputLayout, you surely can, as the library supports API 22+, but for the lower versions you should probably input text by adding classic EditText. You add both of them to your XML, hide them, and then based on user's API you show one or other.
Also, read this document.
https://developer.android.com/training/basics/supporting-devices/platforms.html
Especially this should help you get an idea what and how to do it:
private void setUpActionBar() {
// Make sure we're running on Honeycomb or higher to use ActionBar APIs
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
Good luck :)
I'm new to android studio and I have a new version installed (version 1.5.1).
For some reason I keep getting an error message (every time I use an app theme) saying that there were rendering problems: styles missing.
I looked online for solutions, but most of them are outdated or just do not work.
Thanks for any help.
Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.easycodingplus.myapplication">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Build gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.easycodingplus.myapplication"
minSdkVersion 8
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}
just change your style.xml file like this
<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>
and then, go to
File > Project Structure > app >
and set (both should be same with latest version )
source compatibility : 1.7
Target compatibility : 1.7
you have to include the dependencies for design which is like this, this will be added under the dependencies block of the app module of the build.gradle
compile 'com.android.support:design:23.1.1'
it should be something like this ..
you need this support library as CoordinatorLayout, AppBarLayout and FloatingActionButton part of it
make a style in the style file
<style name="AppTheme" parent="Base.Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
and reference that in your AndroidManifest file
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="#style/AppTheme">// like this
Please ensure you have the lateset AppCompat library listed as a dependency in your build.gradle file:
com.android.support:appcompat-v7:23.1.0
Can you post which style the error is referring to? You may need to add a style to your res > values > styles folder. Something in your code is probably referencing a style that does not exists in that folder.
try this way:
keep your internet connection
go to "file" in android studio toolbar click on "invalidate caches/Restart" and choose "invalidate and restart"
3 options
1.Select low-level API version
2.Add Base on styles.xml
3.Install previous SDK (if you want)
I also faced the same problem so what I did...go to sdk manager -->tick android 5.1.1 api level 22 and installed it....
then go to Preview window and select other version
I faced the same problem and these steps helped me solve it:
1. File > Other settings > Default Settings > Appearances & Behaviour > File encoding.
2. Change project encoding to windows-1252. Then:
3. File > Invalidate Chaches/Restart.
OR WORST CASE
Change the theme to Material light or something else, one of them should work.
I hope this helps.
Recently I upgraded my nexus 5 to Lollipop. and I create an app using AppCompat-21. The styles under values-v21 are as follo
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light">
</style>
</resources>
but when I run the app, it crashes with the information:
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
here is my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "geone.businspector"
minSdkVersion 11
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.0'
}
It runs great under the device pre-Lollipop...
I googled a lot and had no good solution. anybody met this before? ps: I'm using Android Studio 0.8.14 and I'm new to Android Studio. thx.
The error clearly states that you're using the wrong theme. The activities you're using are from the android.support package, these activities need a ThemeCompat theme, not the Theme.Material.Light, which is for activities in android.app package. Rewrite your theme like so:
<resources>
<style name="AppTheme" parent="Theme.AppCompat">
</style>
</resources>
And this error will be gone.
Under your values/styles.xml you would be using Theme.AppCompat.Light
Use the SAME parent theme for your values-v21/styles.xml as well. This will get rid of the error as it did for me.
On Lollipop devices the theme works like it actually should so no worries :)
So I had the same issue and I got soooo tired of Googling it and seeing persons say not to use the Material Theme. Not using Material Theme changes the actionbar to gray even when you set a color for it in styles.
Anyway, the fix is that the android templates created by android studio use import android.support.v7.app.ActionBarActivity; instead of import android.app.Activity; and extend ActionBarActivity instead of activity for the main class. Just change the main class to extend an Activity instead of an ActionBarActivity. Of course more changes will have to be made if you are not using a Blank activity.