Android ActionBarCompat library - android

I'm having trouble using ActionBarCompat support library which was released yesterday. I have updated support repository and included path to appcompat-v7 repository in build.gradle as Chris Banes pointing out in DevBytes - https://www.youtube.com/watch?v=6TGgYqfJnyc .
dependencies {
compile ('com.android.support:support-v4:18.0.+')
compile ('com.android.support:appcompat-v7:18.0.+')}
Build goes well and I can use classes such as ActionBarActivity from this library but I cannot use styles and any resources so I cannot use following themes - #style/Theme.AppCompat etc. I was thinking that I'll find source files in .../sdk/extras/android/.../"supportrepo" so I would reference it like ActionBarSherlock by gradle but that didn't seems to be the correct answer.
What am I doing wrong? Thank you.

I'm using Android Studio and I have the same res-resolving issue in the my values/styles.xml.
It says it cannot resolve #style/Theme.AppCompat.Light, but at compile-time (gradle) and runtime everything works fine (Android 2.3.3 & 4.3).
I'd like to get rid of the warning that the res cannot be resolved.
How can I tell Android Studio that this res can be found in the appcompat-v7 repo?
(This question was related to a bug in Android Studio that has already been fixed.)
Below you see what I did. I hope this will help. Suggestions appreciated.
The source for the appcompat library can found on github.
Gradle integration:
dependencies {
...
compile group:'com.android.support', name:'appcompat-v7', version:'18.0.+'
...
}
Style-files:
values/styles.xml:
<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="android:Theme.Holo.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="#style/Theme.AppCompat.Light">
<item name="actionBarStyle">#style/ActionBar.Solid.Custom</item>
</style>
<style name="ActionBar.Solid.Custom" parent="#style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="background">#drawable/ab_solid_custom</item>
<item name="displayOptions">homeAsUp|showHome|showCustom</item>
</style>
</resources>
values-v14/styles.xml:
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 14 theme customizations can go here. -->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/ActionBar.Solid.Custom</item>
</style>
<style name="ActionBar.Solid.Custom" parent="#android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:background">#drawable/ab_solid_custom</item>
<item name="android:displayOptions">homeAsUp|showHome|showCustom</item>
</style>
</resources>
MainActivity (only the extend is mandatory):
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Views.inject(this);
setupNavigationDrawer();
}
}
AndroidManifest.xml (setting android:theme is mandatory):
<activity
android:name="com.example.app.MainActivity"
android:theme="#style/AppTheme"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

There is a known bug (http://code.google.com/p/android/issues/detail?id=56312) where the Android Studio IDE will flag the style as red (that bug is for ActionBarSherlock, but the issue is to do with an aar containing styles and the sources for that aar not being visible to Android Studio).
Specifically, comment #8 (http://code.google.com/p/android/issues/detail?id=56312#c4) shows the observed behaviour, and comment #10 (http://code.google.com/p/android/issues/detail?id=56312#c10) notes that the layout editor is fixed, but the code editor is not.
Thus, the program should build & run fine, just show the style in red when viewed in the XML style editor.

I have not tried Gradle yet so I am not sure but it seems you also need to copy resources into your project.It contains Theme.AppCompat.
I got success in Eclipse by following below steps.
Import android-support-v7-appcompat as a libray project from below path.(you might have saved sdk on different path)
D:\adt-bundle-windows-x86\adt-bundle-windows-x86\sdk\extras\android\support\v7
The I just added this library into my project and things worked out of box.

I also added the same 2 lines to my dependencies section in the build.gradle file. Compiling started to work but I got runtime errors. Then I discovered the option Tools > Android > Sync Project with Gradle Files. This seemed to do the trick. (I'm on Android Studio 0.2.9)

In my case, Lastest Studio 0.8.1
Create new project and set Style to AppTheme. then crash.
My solution:
File -> Project Structure -> Dependicies -> + (plus) -> select appcompact, support, ....
And error fixed.
thanks.

Cf https://plus.google.com/113735310430199015092/posts/ef5LyGyMddy
David Van de Ven
Except someone forgot to update the support repository, so anyone
using android studio will have their gradle builds break when trying
to use the new support library.
Roman Nurik
+David Van de Ven we're working on that.

Related

Android Studio Rendering Problems (No preview)

I have just installed Android Studio and I am a beginner in app programming. I got the following error when I first launched the Android Studio.
Rendering problems
The following classes could not be found
- android support.v7.internal.widget.ActionBarOverlayLayout (Fix_Build_Path, Edit_XML, Create_Class)
Tip: Try to build the project
What might be the cause of this error and how should I fix it?
Changing AppTheme parent in res/values/styles.xml resolved this problem. Replace
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
with
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
Downgrade API level from 22 to 21 in Preview Pane

error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.NoActionBar'

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

Android material design in Eclipse

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.

Android development through Eclipse

I try to use the android development tools trough Eclipse Luna.
Exactly I try to use the JBoss for cordova developmet
I have a problem to run the Android emulator. So I tried first to create a clear Android Application project and it have the following error.
What should I do to fix them and run the emulator properly?
styles.xml
<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>
</resources>
ActionBar is found in support library v7. Maybe it's missing.
You can right click in your project -> Properties -> Android
There you should see a library added with a green mark like the following:
If you don't have any library there, you should import the library by going to: File -> Import -> Android -> Existing Android Code Into Workspace
Then look for your library v7 into the sdk folder like the following picture:
Then click finish:
And go back to right click on your project and go to properties to add the library by clicking in the Add... button and selecting the library:
Hope this solves your problem!

appcompat_v7 library error in eclipse when create new application

I am working with eclipse juno and when i create new application so it contain error.
I am go through with following solution but still the error is there.
1. clean and build the application
2.Add the appcompat_v7 library
please help me to fix this error.![I have added and clean the project but still the error are there][2] [2]:
Do as directed:
Delete appcompat_v7 library library from your project. You will find some errors in your main project.
You will find errors in your styles files in the values folder.
(i) Apply the following lines of code in the styles.xml of your values folder which contains error:
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>
(ii) Apply these in styles.xml of values-v11 folder:
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>
(iii) Apply these in styles.xml of values-v14 folder:
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>
Inside menu folder, replace app:showAsAction="never" with android:showAsAction="never"
Finally in your MainActivity replace ActionBarActivity with Activity. Remove all the unnecessary imports.
Now hopefully, your project is ready to run.
That is may be because you are not added the appcompact_v7 support jar file to your project properly.Check this link How to add support libraries? will be helpfull.dont forget to restat your eclipse after adding the jar file.
1)add your support library to your project explorer.
2)add jar file inside it to your android project,as suggested in the above link.
3)clean and build your project(or restart eclipse).

Categories

Resources