Failure to change Theme in Android Studio - android

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.

Related

How to solve this below issue?

I have a background service and i am doing some long running task. Based on some conditions i am showing AlertDialog to the user . I have used AppCompatButton in that alert dialog layout. Will it cause any issue like mentioned below. What is the way to solve it.
View class androidx.appcompat.widget.AppCompatButton is an AppCompat widget that can only be used with a Theme.AppCompat theme (or descendant).
That means your app theme must inherit from one of Theme.AppCompat themes. Go to themes.xml (or styles.xml if it's an older project), check the parent field of your theme, and change it with one of Theme.AppCompat themes:
ex: Theme.AppCompat.Light.DarkActionBar (any other theme that inherits from Theme.AppCompat could work as well)

MaterialCardview requires Theme.AppCompat

I'm trying to test my skills on new Google Material components.
But for now I am encountering a problem with MaterialCardView
The building process tells me
The style on this component requires your app theme to be Theme.AppCompat
[..]
at com.google.android.material.card.MaterialCardView.<init>
With this clue I added
style="#style/Theme.AppCompat" & android:theme="#style/Theme.AppCompat" to the MaterialCardView and also to my Activity in the manifest.
I tried also to change my Acitivity to AppCompatActivity but without any success.
I also tried to set styles told by material.io documentation but without success !
Have you some clues?
Thanks
According to Material Components 1.2.1 you need to do this:
Depend on the library implementation 'com.google.android.material:material:1.2.1'
You'll need to have compileSdkVersion 30
Your activity needs to extend AppCompatActivity (or use AppCompatDelegate)
You have to use a Material Components theme
Source: https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md
The easiest way to get started is for your current theme to extend Theme.MaterialComponents.*.Bridge instead of Theme.AppCompat.*.
Additionally you'll need to override the following attribute in your theme, otherwise the card color will be broken:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar.Bridge">
<item name="elevationOverlayEnabled">false</item>
</style>
Don't set android:theme="#style/Theme.MaterialComponents" on the card. You'll lose color information (primary, secondary, accent,...) from your theme on every widget inside the card.
Don't set style="#style/Theme.MaterialComponents on the card. Don't mix themes and styles.

Using design library with Theme.Material [duplicate]

I'm trying to understand the principles of using Material Design a bit better (I'm new to this area and have been reading documentations and tutorials, but the subject is still a bit vague to me), and I'll be glad for some help. What I've tried so far is having 2 folders (values and values-21) with a styles.xml file per each of them -
values/styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"></style>
values-v21/styles.xml:
<style name="AppTheme" parent="android:Theme.Material.NoActionBar"></style>
The problem begins where I try to use activities that inherit from AppCompatActivity (To my understanding, that's what I need to do in order to support backwards compatibility on devices before Lollipop for things such as Material Design? Am I correct? More info here would be great). If I do that, the app won't run on devices that have API 21 or above, since "AppTheme" has to inherit from AppCompat.
What I can do to solve that, is to create a base theme that inherits from AppCompat , and then make the style in both files to inherit from that base theme... But then I'm not inheriting from Material anymore.... which brings me to the question(s) -
Is Material Design just a given theme? And if so, how do I solve my problem? And what does using AppCompatActivity exactly accomplish here? Or is Material Design essentially just a set of rules and principles I'm supposed to follow? And if so, why do we need Theme.Material.* at all? I'll be glad for any extra info anyone can give me on the subject.
Thanks!
The whole point of AppCompat is that you only need one theme (you don't need a separate one in values-v21) and it will be the same experience on all devices.
Theme.AppCompat already extends android:Theme.Material on API 21+ - it is just handling all of the version checking for you.

Material Design, AppCompat, and Backwards Compatibility

I'm trying to understand the principles of using Material Design a bit better (I'm new to this area and have been reading documentations and tutorials, but the subject is still a bit vague to me), and I'll be glad for some help. What I've tried so far is having 2 folders (values and values-21) with a styles.xml file per each of them -
values/styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"></style>
values-v21/styles.xml:
<style name="AppTheme" parent="android:Theme.Material.NoActionBar"></style>
The problem begins where I try to use activities that inherit from AppCompatActivity (To my understanding, that's what I need to do in order to support backwards compatibility on devices before Lollipop for things such as Material Design? Am I correct? More info here would be great). If I do that, the app won't run on devices that have API 21 or above, since "AppTheme" has to inherit from AppCompat.
What I can do to solve that, is to create a base theme that inherits from AppCompat , and then make the style in both files to inherit from that base theme... But then I'm not inheriting from Material anymore.... which brings me to the question(s) -
Is Material Design just a given theme? And if so, how do I solve my problem? And what does using AppCompatActivity exactly accomplish here? Or is Material Design essentially just a set of rules and principles I'm supposed to follow? And if so, why do we need Theme.Material.* at all? I'll be glad for any extra info anyone can give me on the subject.
Thanks!
The whole point of AppCompat is that you only need one theme (you don't need a separate one in values-v21) and it will be the same experience on all devices.
Theme.AppCompat already extends android:Theme.Material on API 21+ - it is just handling all of the version checking for you.

Extending AppCompatActivity not letting me use Holo or Material themes

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

Categories

Resources