I added the AppCompat V7 library to add some Material Design elements to the UX of an app that has to support older devices (android:minSdkVersion="16")
I was able to add the Theme.AppCompat.Light theme to my app and even did some customizations of the action bar with #style/Widget.AppCompat.Light.ActionBar.Solid.Inverse. The problem comes when I try to do the simplest changes to the main theme, like changing colors as follow:
<style name="Theme.AppBaseTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimary</item>
</style>
I keep getting this error: error: Error: No resource found that matches the given name: attr 'colorPrimaryDark'..
I already checked that the build targets for the project and AppCompat are the same, but with no luck.
I think it has something to do with refering to the resources from the library, because when I copy the themes.xml file to my project, it works.
Is that the way I'm supposed to do it? Wasn't the library there to contain all the resources I need so I wouldn't have to copy them manually?
Thanks!
Build targets for your project and AppCompat-v7 need to be both level 21.
Related
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textColorPrimary">#color/colorTextPrimary</item>
<item name="android:textColorSecondary">#color/colorTextSecondary</item>
</style>
This is the styles.xml file. The following code results in this error - i have put all the necessary libraries and jar files and i have also tried changing the syntax little bit and many stuff but I am not able to solve the problem. It is very important. Please help me. Thank you.
I have tried the following :
You need to reference this AppCompat library in your Android project.
Import the library into Eclipse.
Right click on your Android project.
Select properties.
Click 'add...' at the bottom to add a library.
Select the support library
Clean and rebuild your project.
It still doesn't work.
Edit now :
I have installed android sdk 5.0 (API 21) but it still doesn't work. The line with the error is
There were 3 other errors before installing android sdk 5.0 (API 21) in this file (styles.xml) but now they are gone. Please help me to remove the remaining error.
If you are using material in the manifest, you will get this error if your min version isn't API 21
Is there any way to create an app with Material design in Eclipse? Hamburger to arrow animation, full screen height navigation drawer...
Yes you can create an app with material design using eclipse.
Please follow each steps below carefully without any error.
Steps:
Create a new Android Project with Target SDK version 21. If your project already exists then just change the Target SDK version.
Add Appcompat v7 lib to your workspace and add this lib to build path of your project. You can find this lib at sdk\extras\android\support\v7.
Set Project build target to version 21.
There should be only 2 values folder in res folder.
values
values-v21
values/styles.xml should be as below.
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
....
// Your style here
</style>
values-v21/style.xml should be as below.
<style name="AppBaseTheme" parent="#android:style/Theme.Material.Light.DarkActionBar">
....
// Your style here
</style>
You can find different style attributes here https://developer.android.com/training/material/theme.html
After following above steps, your app will be ready with material design theme.
Now your second question regarding navigation drawer you can use following link for simple and step by step implementation.
Part 1 http://www.android4devs.com/2014/12/how-to-make-material-design-navigation-drawer.html4
Part 2 http://www.android4devs.com/2015/01/recycler-view-handling-onitemtouch-for.html
This implementation uses recycler view. For that you need to add recycler view lib (location - sdk\extras\android\support\v7) to your project and add it to build path.
You can develop apps with Material Design in Eclipse by using the libraries provided by google. You need to follow the below steps to do that.
Properties> Android> Add...>appcompat_v7
Add...> Android Design Support Library(You can import it from android-sdk\extras\android\support\)
Add...> RecycleViewLibrary & CardViewLibrary libraries for RecycleView and cardView, better material look and feel. (You can import it from android-sdk\extras\android\support\v7\)
Add/Edit values\styles.xml
<style name="MyMaterialTheme.Base" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Change theme in AndroidManifest.xml file. android:theme="#style/MyMaterialTheme"
extend your Activity by AppCompatActivity.
Hope you can develop Material Designed apps in Eclipse throgh these steps.
Important: Support for the Android Developer Tools (ADT) in Eclipse is ending. You should migrate your app development projects to Android Studio as soon as possible.
I'm struggling with disappearing R.class due to some problem in styles.xml - it says
Error retrieving parent for item:
No resource found that matches the given name 'Theme.AppCompat.Light'.
Problem appeared while exporting project to another laptop....
styles.xml below.
Thanks in advance.
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
This means you do not have the support library in your build path on your new machine. See the adding support libraries with resources section of the docs for your answer.
First of all I suppose you tried Project -> Clean or to close and re-open eclipse itself. Then you must ensure of adding support libraries as said up.
Lack of R file can be caused by many reasons.
Possible Solutions
Sol 1. Since it is associated with Theme.AppCompat.Light( which is defined in support library) it may be caused by lack support library in your build path(Appcompat).
Sol 2. Check the version of appcompat and make sure you have the latest one.
Sol 3. Just to be sure. Undo latest changes done in any xml files( or replace the xml file from history).
Sol 4. If you have already added support library and the problem still exists then delete android-support-v4.jar from lib folder if present( this is because conflicting support jar files can cause R file errors).
Sol 5. Check Project Build Target.(Project>Properties>Android)
You can also make sure 'Theme.AppCompat.Light' is present in your support library by placing the cursor between the text(Theme.AppCompat.Light) and press control button which should underline the whole text.
I hope it helped..
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.
I'm trying to add the support action bar to my Android app, but right at the start where I have
<style name="AppBaseTheme" parent="android:Theme.AppCompat.Light">
I get an error No resource found that matches the given name: android:Theme.AppCompat.Light.
I can import android.support.v7.app.ActionBar and android.support.v7.app.ActionBarActivity so I think I've added the support libraries correctly. Why do Android dev docs gloss over this? It should be Lesson #1.
It should be:
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light">
android:Theme.AppCompat.Light is incorrect. Everything with the namespace 'android' refers to properties from the framework ( but Theme.AppCompat.Light only exists in the support library).