I have trace Holo.Theme.Light.DarkActionBar with value-11, and see this:
<style name="Theme.Sherlock.Light.DarkActionBar" parent="Sherlock.__Theme.DarkActionBar">
...
<item name="actionBarStyle">#style/Widget.Sherlock.Light.ActionBar.Solid.Inverse</item>
...
</style>
And Theme.Sherlock.Light.DarkActionBar, is an ancestor of Holo.Theme.Light.DarkActionBar.
So, if I want to derive a new theme, why I have to cover "android:actionBarStyle" for level>=11 ?
Could anyone help me?
Thanks
ActionBarSherlock uses its own implementation to draw the ActionBar on pre level 11 devices. For this case the styles that apply to ActionBarSherlock are used. On devices with level 11 or higher, the native ActionBar is used and so only the styles for this component are used. On Android 3 or 4, the app just behaves like ActionBarSherlock would not be used in your project.
Related
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 ActionBar in API level 8-10. i search solutions and find out 2 links bellow, but they are not useful for me.is there someone who has the same experience?Thanks!
this is my code:
ActionBar actionBar =getActionBar();
assert actionBar != null;
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#e32238")));
link1
link2
when i run the proje,these errors are shown:
ActionBar added in Android 3.0 (API level 11), but you can use it in ealier API 11 by using Spport Library. To use support library for Action Bar, your activity should extends ActionBarActivity.
To custom your action bar color, you can set actionbar style in styles.xml file, something like:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<!-- for before API 11 -->
<item name="background">#color/your_color</item>
<!-- for after API 11 -->
<item name="android:background">#color/bg_blue</item>
</style>
Hope this help!
[UPDATE]
To use AppCompat theme, you have to import AppCompat library to your project from support library V7: your-android-sdk\platforms\extras\android\support\v7\appcompat
In one of my projects, I used ActionBarSherlock.
Download the abs here.
Assuming you're using Eclipse IDE, right click your project, click properties, then android. At the bottom, in layout, add abs.
Make sure abs and your project are in the same directory.
Extend your classes to Sherlock naming. For example, instead of Activity, change it to Sherlock Activity. The main documentation of abs is found here.
For easier usage of Sherlock, create util methods in changing the Sherlock names and modifying it.
Here is a sample code.
I switched from ABS to AppCompat and Material theme(for api 21 only)
<!--manifest: -->
<application
android:theme="#style/AppStyle"
<-- values folder -->
<style name="AppStyle" parent="#style/AudioRecTheme">
<style name="AudioRecTheme" parent="#style/Theme.AppCompat.Light">
<!-- values-v21 folder-->
<style name="AudioRecTheme" parent="#android:style/Theme.Material.Light">
My activity:
public class AudioRecActivity extends FragmentActivity
The action bar is showing only in Android 5.0, but missing otherwise.
First, either use appcompat-v7 or use built-in themes, not both for the same activity. Here, you are trying to use Theme.AppCompat.Light in some cases and Theme.Material.Light in others, which is not only unnecessary but AFAIK will not work. If you are going to use Theme.AppCompat.Light, do so for all API levels.
Second, if you are going to use appcompat-v7 and Theme.AppCompat.Light, you need to inherit from ActionBarActivity.
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.
Hello i use ActionBarSherlock Version 4.0.0 and i dont know how to change/style the title text, under version 3.5 i used #style/abTextStyle.
but that doenst work in version 4.0.0.
ABS 4 brought with it some major improvements, one being the styling via XML. If you read the documentation on styling, you would know that as of 4.0 -
Due to limitations in Android's theming system any theme
customizations must be declared in two attributes. The normal
android-prefixed attributes apply the theme to the native action bar
and the unprefixed attributes are for the custom implementation. Since
both theming APIs are exactly the same you need only reference your
customizations twice rather than having to implement them twice.
<style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
From this we can see that the ABS item reflects the native exactly, obviously without the android prefix.
This in short means that styling the native and ABS actionbar is now much simpler and to do any styling you should follow the standard Android docs on this, and then declare the styling you want like the example above (i.e. declare twice, once for native once for ABS).
This question ActionBar text color has some examples for what you want in its top voted answer, and if you want to be comforted: it was commented on by Jake Wharton who is the genius behind ABS.