I have removed the ActionBarSherlock library and adapted my code.
Now I get errors in my style.xml
<style name="Theme.MyTheme" parent="Theme.Sherlock.Light">
What do I have to use instead of the Sherlock.light theme?
If you are using AppCompat library, use AppCompat.Light
#style/Theme.AppCompat.Light
else Try using Holo.Light.
#android:style/Theme.Holo.Light
If you are migrating to appcompat-v7, you need to migrate all Sherlock references to their corresponding AppCompat equivalents. This includes switching custom themes to inherit from Theme.AppCompat (e.g., Theme.AppCompat.Light).
You might consider installing Android Studio, then creating a scrap project using the new-project wizard. The defaults will use appcompat-v7, and you can examine the newly-created project to see what it uses, to help you determine how to change your Sherlock references.
Related
I don't really like Material design's spinner, and AppCompat doesn't contain the Holo Theme anymore. Should I revert back to AppCompat when it still supported Holo Theme or is there another way ?
With AppCompat v22, if you are using an AppCompatActivity you have to use an AppCompat theme.
If you try to use another theme you will receive:
Caused by: java.lang.IllegalStateException: You need to use a
Theme.AppCompat theme (or descendant) with this activity.
The only way to use a Holo Theme is to use a lower version.
e.g.
compile 'com.android.support:appcompat-v7:19.1.0'
I'm quite confused about how styling in appcompat library works.
According to here:
We now use the support implementation of Toolbar/ActionBar on all
platforms meaning that we no longer read any android: attributes
related to the action bar.
For apps which already have existing appcompat setups, this means that
you should remove your v14+ themes which re-set the same values in the
android namespace. Please note, this is ONLY applicable for
styles/widgets which affect the action bar.
For most apps, you now only need one theme declaration, in values/
So here is my question:
If I want to use material design ActionBar in API 14+, I can just use ActionBar/Toolbar provided in appcompat_v7 and style it in the common value/ folder with the "android:" namespace removed ? but why am I seeing people writing code below:
<style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
....
<item name="windowContentOverlay">#null</item>
<item name="android:windowContentOverlay">#null</item>
....
</style>
why is "android:" namespace there? what's the difference between the code above and using value-v21, value-v14, folders?
can someone explain or direct me to the right source?
Yes, if you use AppCompat v21+, you only need a single theme with a parent of Theme.AppCompat (or a subtheme such as Theme.AppCompat.Light) and you do not need the android: namespace attributes for action bar/window related flags, nor separate themes for v14, v20, etc. The full list of top level attributes which AppCompat provides across all API levels can be found in the AppCompat R.styleable Theme.
Much of the code on the internet (including parts of the developer.android.com site) are still written for the pre-v21 AppCompat, which did require both the android: and non-prefixed versions.
I want to use Material Theme in my application which has minimum sdk version of 8. As per docs - "The material theme is only available in Android 5.0 (API level 21) and above. The v7 Support Libraries provide themes with material design styles for some widgets and support for customizing the color palette." Does it mean I can use it if I add v7 Support Libarary in my project? Because after adding this library I got the following error:
android:Theme.Material.Light requires API level 21 (current min is 8).
Or maybe I understood something wrong? Any suggestion will be appreciated. Thanks in advance.
For this you need to have 2 values folders.
One that exists by default, and another, you have to create in your res folder and name it values-v21.
In the default values folder, in styles.xml, use a theme other than Material theme.
And in the styles.xml of values-v21 folder that you created, use Material theme.
Android phone will automatically pickup the styles.xml which it supports. If the phone supports Material Design (Lollipop devices), your app will use Material theme (values-21 folder).
If it doesn't (in phones running older Android versions), the default values folder will be used.
You need to use android:theme="#style/Theme.AppCompat.Light" theme to get a material design.
Make sure your min is 8 and your target is 21. And you're using build tools/sdk 21.
Pedro Oliveira is right with regards to Theme.AppCompat, but some essential information is missing in that answer.
A blog post titled appcompat v21: material design for pre-Lollipop devices! by Chris Banes from the Android team probably best answers the question of how to get Material Theme for API levels prior to 21.
To summarise, you need appcompat-v7 dependency:
dependencies {
...
compile "com.android.support:appcompat-v7:21.0.3"
}
After that, for dark version as your base theme, use:
<style name="AppTheme" parent="Theme.AppCompat">
</style>
And for light version:
<style name="AppTheme" parent="Theme.AppCompat.Light">
</style>
And if you're new to AppCompat, there are things you need to know, such as:
All of your Activities must extend from ActionBarActivity*. It extends
from FragmentActivity from the v4 support library, so you can continue
to use fragments.
*NB: more recently, ActionBarActivity has been deprecated in favour of AppCompatActivity.
But you really should read the whole Setup section of that blog post! (The information on Toolbar vs Action Bar, and some of the comments are also something you probably shouldn't miss.)
In your NameActivity.java file import the following:
import android.support.v7.widget.Toolbar;
Comment the previous one:
//import android.widget.Toolbar;
With this the problem is solved.
I am trying to change the android action bar style. The minimum API support for the app is 8. So as using android:actionBarStyle attribute in the style xml file in the values folder gives the minimum required API 11 error, I have commented it out and moved it to a separate style xml file in v11 folder.
However, when using the actionBarStyle attribute only for android 2.1 and higher as mentioned in the android documentation, it gives me the No resource found error. Below is the style code:
<style name="AppTheme" parent="android:Theme.DeviceDefault">
<item name="android:typeface">monospace</item>
<!-- <item name="android:actionBarStyle">#style/MyActionBarTheme</item> -->
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
I have tried changing the style parent theme from DeviceDefualt to Holo.Light.DarkActionBar, AppCompat.Light.DarkActionBar, etc. but the error still remains.
If you want to use the standard Action Bar on Android devices v7 appcompat library, which backports the Action Bar to any API 7+ device when you use ActionBarActivity. (Note, the Android documentation you found reference this same library, hence the 'When using the Support Library' comments throughout that document)
To add it to your project, you can follow the directions for adding a library with resources for whatever IDE you use.
Once you have the appcompat library added, you may consider using a tool like the Android Action Bar Style Generator which automatically builds the correct styles/resources needed to fully style your action bar (make sure to change the 'Style Compatibility' drop down to 'AppCompat').
Since google released the new support library v7, I use the appcompat library instead of actionbarsherlock. With the appcompat library the actionbar still works, if I disable the recreating at orientation change (android:configChanges="orientation|screenSize|keyboardHidden"), which saves me a lot of work. But for the user experiece of android >=2.1 and <3.0 users, i would be happy, if I could continue to use holoeverywhere (which depends on ABS).
I've tried to setup ABS as library for holoeverywhere and then AppCompat and holoeverywhere as libraries for my App, but it doesn't work.
I'd appreciate your help.
EDIT:
I haven't found any solution to get them work together. But I found out, that I can use the Holo Style Generator (link) to change the drawables of most UI components (e.g. EditText etc.). After the theme is generated, you only have to change the parent style in the files from:
res/values/themes_apptheme: <style name="AppTheme" parent="android:Theme.Black">
res/values-v11/themes_apptheme: <style name="AppTheme" parent="android:Theme.Holo">
to
<style name="AppTheme" parent="#style/Theme.AppCompat">
Probably a little late now, but newer versions of HoloEverywhere come with AppCompat instead of ABS.
Personally I tend to struggle with this, as porting ABS projects to AppCompat turned out to be a pain, but there are definitely advantages of using the 'official' solution in the long run.