I have a fairly simple app in android which uses the Support Library to provide an Actionbar for devices running on APIs lower than 11, so my main activity extends the AppCompatActivity.
My current app theme is as follows:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
After running some tests and making sure the app works as expected, I've decided to set the theme for devices running on API level 14 and above as follows:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
The app has been crashing on startup ever since.
The logcat shows that an exception is being thrown, which says the following:
You need to use a Theme.AppCompat theme (or descendant) with this activity.
Does it mean that I must use only the AppCompat themes, regardless of the device's API?
If not, then how should I solve this issue?
Does it mean that I must use only the AppCompat themes, regardless of the device's API?
Yes. Or, stop using appcompat-v7, and inherit from Activity.
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+
My Android App :
Target API:22
Min API:15
Device run on :API level 22
I don't understand this whole theme concept ,
In my manifest.xml ,I have set android:theme="#style/AppTheme"
and all activities use this theme
Now my understanding is that they all use the theme called AppTheme which I can now define by extending other themes inside my styles.xml
In my styles.xml
I have this
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
My understanding is that AppCompat themes allow us to use newer(say material themes) on older devices also .
I run this app on API Level 22 and API Level 15 , it works fine
Now when i change it to
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- Customize your theme here. -->
</style>
</resources>
It gives a warning saying this theme can be used only on API 21 or above which is correct , now when I ignore the warning and run it in on API 22 it crashes.
Why?
Also I tried to make AppTheme's parent as Holo , Light etc ,all of them crash the App , why , please explain?
All of these end up crashing the App
<style name="AppTheme" parent="android:Theme.Translucent">
<style name="AppTheme" parent="android:Theme.Holo">
Why do these not work , Holo was introduced in 15 right?
I am using 22 ,
and can you please elaborate the difference between
Theme....., BaseTheme....,Android..... themeName
And i am running android studio 1.3 and using the latest versions(Stable) of the SDK,SDK build and SDK-Platform tools.
Thank you !
Sorry , I found the issue , My activity was extending AppCompatActivity instead of the general activity ,I get it now
When ever working with custom styles you have to take care of the parent you are providing. Try to change the parent theme and it might solve your problem.
I'm running the latest version of android studio ,Problem is the preview pane does not render the ActionBar when any of the AppCompat themes are used, if i change the theme of the preview pane it works fine(Not change actual theme) ,but is there any discepency in doing this,
my styles.xml is as follows
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
when the preview pane is set to AppTheme ,the ActionBar ain't shown ,however it works fine in my device and AVD,
As you can see this makes it hard to debug and test the ActionBar
Please suggest some fix to this and how exactly does a AppCompat theme differ from an ordinary one?,I'm just an android beginner .
Thanks!
It is a bug: https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=78944
Unfortunately it is low priority.
Update: set the preview to API 22
In my styles.xml I had
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
had to change it to just
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
There is culprit in your MainActivity(which ever your activity) when your are using app.compact.v7 your are supposed to extend ActionBarActivity instead Activity
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+.
I'm trying to implement the holo theme for my app, so far so good...
but the app didn't work on older devices pre 3.0
so I made a custom theme, in values dir and values-v11 dir to make android switch to the correct one on runtime...
I also set the target sdk level to 7 to support android 2.1
now the holo theme isn't recognized
Am I aiming for something impossible?
What I want is pre 3.0 devices to use the default android theme
and everything that supports holo to use holo theme.
In values/styles.xml:
<style name="AppTheme" parent="#android:style/Theme.Light">
values-v11/styles.xml:
<style name="AppTheme" parent="#android:style/Theme.Holo.Light" />
values-v14/styles.xml:
<style name="AppTheme" parent="#android:style/Theme.DeviceDefault.Light" />