I have integrated navigation drawer in my app with android-support v7 for minSdkVersion="8" devices. I want to customize navigation bar´s theme but if I use the following code I can´t because requires API level 11, how can I do? Thank you
<style name="MyActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#drawable/press</item>
</style>
See the documentation here:
https://developer.android.com/training/basics/actionbar/styling.html
In particular, look at the Theme.AppCompat part.
As you note the parent theme requires API 11. To avoid this use one of the AppCompat themes that are included in the v7-support-library, defined in the R.style resource
Related
In My case, what is difference in here:
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
and
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
This is the raw material design theme, which is used by Android 5 and upNot sure how this works wrt. new Android libraries for app design:
<style name="AppTheme" parent="android:Theme.*">
This is a way to use material design on pre-lollipop devices, which maintains compatibility.
<style name="AppTheme" parent="Theme.AppCompat.*">
You can design for newer APIs using AppCompat and still have it work on earlier API levels than what the base level for material design is.
In this case, it essentially means that you can run material design on platforms that predate material design. This isn't as important anymore now that versions that early make up at most ~2.5% of the market share at the time of writing.
Note, however, that using AppCompat does give you additional compatibility helpers beyond just being able to use the material theme on older devices. Also note that AppCompat has since been deprecated in favor of whatever system is currently mainstream and that Google hasn't axed yet (Jetpack?), which may or may not work differently.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
Theme.AppCompat is for above API 7+
Theme.Material is for above API 21+
I am running the latest eclipse with the latest Android support library, API 23. by default, the support library along with material design gets added to a new project as far as i know (Compile with API 23).
But i want to change the ActionBar's color, earlier it was not possible on API <11 as it used android's built in library. now i am sure they added action bar in the support library as i tested my project on an android 2.3 device and i see the action bar, so compatibility is not an issue here.
So how do i change my action bar and button's colors?
EDIT::The suspected duplicate does Not solve my problem, i have tried that already, it gives me api level error when i define theme in the styles.xml. i have included the link in my question already.
Edit your styles.xml file. The colorPrimary will be your action bar color and the colorPrimaryDark is the status bar color.
Note: Make sure this theme is set as your activities theme in your manifest.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimaryDark</item>
<item name="colorPrimaryDark">#color/colorPrimaryDarkDark</item>
</style>
I was struggling to make a button style work with API level 16 (with API level 22 was working like a charm). I solved it replacing android:buttonStyle with buttonStyle
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- <item name="android:buttonStyle">#style/button</item> -->
<item name="buttonStyle">#style/button</item>
</style>
Now it works with both API levels, but now my question is:
Why is this happening?
Because
item name="buttonStyle"
is for support library compatibility which your current Theme supports. It is also used on defining other items like actionbar https://developer.android.com/training/basics/actionbar/styling.html
I suggest you define both of it to make it compatible to very wide range of devices
I have a problem with the API Level 21. I want to use the Material Design and still be able to run the application on lower API levels like 18 (Android 4.3.1). But I always get that error:
My manifest SDK looks like that:
And the build.gradle like that:
Hope this is enougth information to get some help, I really need it :(
Cheers.
As described in doc :
https://developer.android.com/training/material/theme.html
Note: The material theme is only available in Android 5.0 (API level 21) and above
This means that you have to use the values-v21 folder for your Material Theme.
However you can use the v7 Support Libraries to provide themes with material design styles for some widgets.
This is an example, using the AppCompat Theme.
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- Here we setting appcompat’s actionBarStyle -->
<item name="actionBarStyle">#style/MyActionBarStyle</item>
<!-- ...and here we setting appcompat’s color theming attrs -->
<item name="colorPrimary">#color/my_awesome_red</item>
<item name="colorPrimaryDark">#color/my_awesome_darker_red</item>
<!-- The rest of your attributes -->
</style>
More info here:
https://chris.banes.me/2014/10/17/appcompat-v21/
I see some application are already supporting material design.
For example the SMS app Textra supports material design. And it works fine on my KitKat.
How can I use the material design on older version of android.
I get error when I use this
<resources>
<!-- your app's theme inherits from the Material theme -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- theme customizations -->
</style>
Is there any solution?
Well... there is a way. Here is a complex answer for you
Material Design from Android 2.2 (API 8) to present 5.0 (API 21)
Here what you need:
Toolbar
Material Design Library for widgets (buttons, checkboxes, etc)
1. Toolbar
Just get the idea and you ready to go.
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimaryDark"/>
Setup guide: http://antonioleiva.com/material-design-everywhere/
Source with example: https://github.com/antoniolg/MaterialEverywhere
To make Toolbar work lower API 11 use Theme.AppCompat.Light.NoActionBar (instead windowActionBar set to false)
<style name="NoActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
</style>
2. Material Design Library
Here is Material Design Library for pretty buttons, etc.. Currently it's heavily developed.
Guide, code, example - https://github.com/navasmdc/MaterialDesignLibrary
Guide how to add library to Android Studio 1.0 - How do I import material design library to Android Studio?
.
Hope it helps :)
There is no direct approach as
<resources>
<!-- your app's theme inherits from the Material theme -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- theme customizations -->
</style>
But in KitKat we can bring the look and feel of material theme without much effort by using Translucent UI.
FLAG_TRANSLUCENT_STATUS or
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:windowTranslucentStatus">true</item>
Check this post for more information: material theme look and feel in KitKat
You can't use it in older version.
But for preventing error you can use specified folders for newer version of values.
Put default style.xml in the values folder, and put specified style.xml for styles for kitkat in values-v19 folder. "Specified" means with attributes that are allowed only in API version 19+.