I'm trying to create an app with android:Theme.Holo.Light and extending the Activity by AppCompatActivity. Android is throwing errors saying that I must use AppCompat theme.
My question is:
If I don't extend AppCompatActivity, I don't get material look in API level below 21 and if I extend Activity and set Holo theme, I don't get any errors but at the cost of missing the Material feel in the older devices. How do I overcome this limitation?
You need to use Theme.AppCompat if you are extending AppCompactActivity
You can use Theme.AppCompat. It is similar to Theme.Holo
Related
I made a custom library. The library has a theme Theme_Amber. I added this library to my project. How can I be inherited in the application of the theme from the library?
I want to be inherited just as inherited from android theme
I wrote this
But the application crash with an error:
You need to use a Theme.AppCompat theme (or descendant) with this activity.
What am I doing wrong?
AppCompatActivity supports only Theme.AppCompat or themes inherited from Theme.AppCompat. If you want to use your custom theme, set it's parent theme as Theme.AppCompat.
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 want to change the Theme to Theme.Holo, but it was crashed when I run the apps. I only made change in Manifest.xml as below, and so far there are no error message shown.
Original:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"></style>
Changed:
<style name="AppTheme_Holo" parent="android:style/Theme.Holo"></style>
Here is the logcat:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
logcat message seem to tell me I can only use the Theme.AppCompat, and I think this theme is coming from supporting library appcompat v7:22.
I have tried to search around the link as below from Android developer site, but seem the setting above has no difference with their suggestion
May I know why I can only use the Theme from the supporting library v7:22?
Is there something I missed to change?
Android Developer site:Styling the Action Bar
Yes there is something more. Your activity is extending AppCompatActivity or ActionBarActivity and that needs a Theme.AppCompat theme or any descendant. You just need to change that to Activity or FragmentActivity from support library v4.
You might be using ActionBarActivity which uses Theme.AppCompat.*. Make your activity extend android.app.Activity to get rid of this error.
When I created a new activity, it extends ActionBarActivity but it's deprecated.
At that moment, I have two options:
1) Used Activity and android:Theme.Material in my style like that :
<style name="AppTheme" parent="android:Theme.Material">
Or
2) Used AppCompatActivity and Theme.AppCompat :
<style name="AppTheme" parent="Theme.AppCompat">
So my question is, what is better between Activity and AppCompactActivity to use Android Material Design and Toolbar ?
It isn't a matter of which is "better". Which one you should use depends on what versions of Android you are supporting.
Theme.Material is only available on devices running API 21 (Lollipop) and up. If you wish to use the Material theme on devices running API 20 and below, you need to use AppCompat.
When I created a new activity, it extends ActionBarActivity but it's deprecated.
This is a very recent change. As of version 22.1 of AppCompat, ActionBarActivity has been deprecated in favor of AppCompatActivity.
setting the sdk minimum 15, should I use Theme.Holo and not Theme.AppCompat
And instead, it is always as if I had given compatibility for Android versions 2.1 and higher.
In this guide: http://developer.android.com/training/basics/actionbar/adding-buttons.html
when I have to add the search action, the ActionBar, are forced to use xmlns: yourapp = "http://schemas.android.com/apk/res-auto"
to be able to give the right showAsAction ...
Same problem to set the Holo theme, this is not available, and returns me error (You need to use a Theme.AppCompat theme with this activity), and are forced to use AppCompat.
I then tried to create a new project with SDK minimun 16, thinking that the problem was on the 15th, and when I go to
res \ values \ styles.xml
I always find parent = "Theme.AppCompat.Light.DarkActionBar"
The only way to use Holo, is creating a project with minimum 21 SDK.
The only way to not use AppCompat is to not use AppCompat. If you extend ActionBarActivity you have to use a theme that inherits from Theme.AppCompat. If you want to use Holo themes, you have to extend Activity.