R Cannot be resolved to a variable. - android

I am trying to run an simple android project from a tutorial, However I am receiving the popular "R cannot be resolved to a variable" error. I have checked my gen folder and the R.id file is not there. This is the list of things I have tried so far:
have done a clean build several billion times.
fixed the project properties
There are no errors in my .xml files and they do not contain uppercase letters etc.
The package name in the source and manifest are exactly the same.
Have installed the latest SDK updates + restarted eclipse.
have deleted the gen file and done another clean build.
There is only an error in the source files, according to eclipse.
Here is a themes.xml file that may be causing a problem:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="android:actionMenuTextColor">#+color/actionbar_text</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#android:style/Widget.Holo.ActionBar">
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText"
parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
</style>
<!-- ActionBar tabs text styles -->
<style name="MyActionBarTabText"
parent="#android:style/Widget.Holo.ActionBar.TabText">
<item name="android:textColor">#color/actionbar_text</item>
</style>
</resources>
Apologies in advance if this sounds familiar, but I have tried everything I have seen from previous posts.
Happy to provide more details if needed. Thanks in advance.

Theme.Holo and Widget.Holo.ActionBar requires API Level 11
TextAppearance.Holo.Widget.ActionBar.Title and Widget.Holo.ActionBar.TabText requires API Level 13
Check your android:minSdkVersion. If it is less than 13 than you can't build your project(or you have to duplicate your styles for different API Levels, using different api level folders under res). eclipse shows this kind of errors.
And also your Android Project Build Target must be at least API Level 13.

Related

Eclipse Android 2.2 project error but Android 4.0 no error

When I create new project for lower android 2.2 label API8 in eclipse there are some error and i can't fixed them. appcompat_v7 inside some problem no found values-v17 - values-v21 and there are also some error my project folder.
After creating ... ...
But when I create project for higher android 4.0 label API(14) there are no error.
After creating ... ...
There are any way to solve this problems.
In 4.0 they use android: prefix for styles but in 2.2 they does not recognise
In 4.0
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CodeFont" parent="#android:style/TextAppearance.Medium">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#00FF00</item>
<item name="android:typeface">monospace</item>
</style>
</resources>
in 2.2
<style name="WindowTitle">
<item name="singleLine">true</item>
<item name="textAppearance">#style/TextAppearance.WindowTitle</item>
<item name="shadowColor">#BB000000</item>
<item name="shadowRadius">2.75</item>
</style>
like wise things changed. So refer the android developer.android.com
Or you can use separate stylesheet from 2.2 . And also without seen the style.xml we cant say that this is the exact problem.
You need to modify your style.xml to ensure API's are supported. Please check this SO post Android AppCompat requires API level 11
This should help you solve the problem you face.

Android Styles.xml Top Level Element Not Completed

I cannot explain nor fix this nagging error of "Top level element not completed" This is a brand new project as in just created.
Here the styles.xml screenshot
And here is part of the Gradle file
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:support-v4:22.1.1'
}
So its not like its missing a reference. The only other thing in the app so far is ToolBar, what else am I missing to make this error go away, I am still able to build and run the app,but the red squiggly line remains, any ideas would be greatly appreciated.
first of all add this
compile 'com.android.support:appcompat-v7:22.0.0' // 21 if your target is 21.
in your style.xml file create base theme..
This means that you have one base theme which will applicable in all version
from 11 to 21 in your case. you can set theme as you want.
<style name="AppTheme" parent="AppTheme.Base">
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/primaryColor</item> <!--do not use android:colorPrimary : older version doesn't recognize it.-->
<item name="colorPrimaryDark">#color/primaryColorDark</item>
<item name="colorAccent">#color/accentColor</item> <!-- in base theme don't use android prefix. it is not supported -->
</style>
above all code in style.xml
Now, you have style.xml(v21)
in that file you need to inherit that base theme.
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:colorPrimary">#color/primaryColor</item> <!--In version 21 you need to provide it as android:colorPrimary : older version only doesn't recognize it.-->
<item name="android:colorPrimaryDark">#color/primaryColorDark</item>
<item name="android:colorAccent">#color/accentColor</item>
<item name="android:windowNoTitle">true</item>
<item name="android:actionBarSize">60dp</item>
<item name="android:textColor">#FFF</item>
</style>
This way, i hope you understand, AppTheme.Base will be applicable to all API.
and plus in 21 it will use specifically with v21. in this way you can set your min sdk version lower as you wanted it to be 11.
Try this.! let me know if it works.!
It might be related to your style inheritance. Maybe try deleting the first AppTheme style, and changing your custom style like this:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">...</item>
</style>
Just make sure you reference this AppTheme name for you activities.
After toiling with this for a few hours, I started to suspect that my Android Studio installation or atleast my Android Studio editor is corrupt and my assumptions turned out correct.
Following instructions here I reset my Android Studio installation to defaults and voila the error went away. For the actual styling one does not have to create a seperate folder -v21 for lolipop devices. Per this post something like this will work.
If you are using AppCompat, then all of the material color palette attributes (such as colorPrimary) are available to all API levels, so you can write a single theme:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
</style>

how to use material design features in api lower than 21 in eclipse?

there are many questions regarding this but not even single helped me.
So please tell me how to enable material design features in eclipse.
i have also imported appcompat_v7 library in project but it does not create a folder with name values_v21 which helps in using those feature i think.
So please help me out in this
here is my styles.xml file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/AppTheme_ActionBar</item>
<item name="android:actionBarSize">#dimen/action_bar_height</item>
<item name="android:windowContentOverlay">#drawable/actionbar_shadow</item>
<item name="android:homeAsUpIndicator">#drawable/ic_ab_up_compat</item>
<item name="android:actionBarTabTextStyle">#style/tabtextcolor</item>
<item name="android:actionOverflowButtonStyle">#style/AppTheme_ActionBar_Overflow</item>
</style>
<style name="AppTheme_ActionBar" parent="android:Widget.Holo.ActionBar.Solid">
<item name="android:background">#color/apptheme_primary</item>
<item name="android:actionBarTabTextStyle">#style/tabtextcolor</item>
<item name="android:icon">#drawable/actionbar_icon_placeholder_compat</item>
<item name="android:titleTextStyle">#style/AppTheme_ActionBar_Title</item>
</style>
<style name="AppTheme_ActionBar_Title" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#android:color/white</item>
<item name="android:textSize">20sp</item>
</style>
<style name="AppTheme_ActionBar_Overflow" parent="android:Widget.ActionButton.Overflow">
<item name="android:src">#drawable/ic_ab_overflow_compat</item>
</style>
<style name="tabtextcolor" parent="#android:style/Widget.Holo.Light.ActionBar.TabText">
<item name="android:textColor">#android:color/white</item>
</style>
</resources>
There are some points you should check:
Import into eclipse, last version of android-support-v7-appcompat
project. You should update via SDK Manager, and import project from {your_path_to_android_sdk}/extras/android/support/v7/appcompat
Add this project as library dependency to your project
In styles.xml use Theme.AppCompat.Light or Theme.AppCompat:
style name="AppTheme" parent="#style/Theme.AppCompat.Light"
A simple guideline:
import the appcompat-v7 project and add it as a library dependency for your project
let your theme inherit some of the appcompat themes. For example <style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
Note that not all widgets (ui elements) are material-styled by appcompat
Follow the examples and explanations in the android-developers blogspot.
The values-vXY folders are used to add specific resources for a specific platform. For example you might add a style (in a values-v21 folder) that inherits some of the material styles that are built-in and available only one api level 21+. These folders are created manually and are only used if you want an alternative resource for a specific platform level. They are used when you want your app to fit better in all/many android versions. More info - at the android developers portal

I don't obtain change color of AppCompat

I'm having the same problem, but I generate a theme via X and after add into my project and I did the correctly references in my styles.xml, however don't work.
My manifest.xml is this:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
Was generated the file below in http://jgilfelt.github.io/android-actionbarstylegenerator
styles_custom.xml, where add in my res/values/styles.xml:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light"> </style>
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="actionBarItemBackground">#drawable/selectable_background_custom</item>
<item name="popupMenuStyle">#style/PopupMenu.custom</item>
<item name="dropDownListViewStyle">#style/DropDownListView.custom</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.custom</item>
<item name="actionDropDownStyle">#style/DropDownNav.custom</item>
<item name="actionBarStyle">#style/ActionBar.Solid.custom</item>
<item name="actionModeBackground">#drawable/cab_background_top_custom</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_custom</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode.custom</item>
</style>
And in res/value-v14/styles.xml
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
<item name="android:actionBarItemBackground">#drawable/selectable_background_custom</item>
<item name="android:popupMenuStyle">#style/PopupMenu.custom</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.custom</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.custom</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.custom</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid.custom</item>
<item name="android:actionModeBackground">#drawable/cab_background_top_custom</item>
<item name="android:actionModeSplitBackground">#drawable/cab_background_bottom_custom</item>
<item name="android:actionModeCloseButtonStyle">#style/ActionButton.CloseMode.custom</item>
</style>
Well someone can help me, or give me the best directions, please?
Thanks
AppCompat is a library project. You need to reference the library project in your android project. So first you need dowload the library through SDK manager .
To download the Support Library through the SDK Manager:-
refer this link:- https://developer.android.com/tools/support-library/setup.html
In this above link read the topic :-Adding Libraries with resources ( It inlcudes so many steps that why I am giving the link )
After completing these steps :-
you can Add the library to your application project:
Step 1:- In the Project Explorer, right-click your project and select Properties.
Step2:- In the category panel on the left side of the dialog, select Android.
Step 3:- In the Library pane, click the Add button.
Step 4:- Select the library project and click OK. For example, the appcompat project should be listed as android-support-v7-appcompat.
Step 5:- In the properties window, click OK
note :-If your app is using the Support Library for compatibility on devices running versions lower than Android 3.0, your custom theme should use Theme.AppCompat theme (or one of its descendants) as your parent theme.

Android 5.0 - Intellij Gradle: Cannot resolve symbol: #color:material_blue_500

I am trying to customize the material design theme as suggested in this link :
android dev
but when I add the following code to my v21/styles file Intellij says that it cannot resolve these symbols.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- customize the color palette -->
<item name="colorPrimary">#color/material_blue_500</item>
<item name="colorPrimaryDark">#color/material_blue_700</item>
<item name="colorAccent">#color/material_green_A200</item>
</style>
</resources>
I looked around to see if there are any particular settings that need to be done on the color side but nothing came up. I am using API 21 with support lib v7 on gradle.
#color/material_blue_500 and others are not the resources in android library.
You must define the color resources in res/values/colors.xml by yourself.
such as <color name="material_blue_500">#5677fc</color>.
And then you can use it as <item name="colorPrimary">#color/material_blue_500</item>.
Android docs are very vague on this, leading to confusion. To get the predefined colors copy color_material.xml to your local res/values dir. That file is a preserved version as it was during Android-L. The offical version which sits in your local directory:
...sdk/platforms/android-21/data/res/values/colors_material.xml
has been trimmed down to remove those color definitions.

Categories

Resources