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.
dependencies {
...
compile group:'com.android.support', name:'appcompat-v7', version:'18.0.+'
...
}
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>