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)
Related
Every time I go to xml file I've to change my theme first to see how my views will actually look, my parent theme is inheriting from MaterialComponents theme and all of the activities are using the same base theme, but still I don't know why in xml it shows Material.Light as my default theme.
and AppTheme is the theme that I want to set to default, is there any way I can do that.
To set or change the default theme, open AndroidManifest.xml and in the application tag, set if not exist or change
android:theme="#style/Material.light"
to whatever you want. You can change theme of individual activity by adding same line in the Activity tag of any Activity.
I want to use the android widget "ChipGroup & Chip" in my app which are from android material 'com.google.android.material', but I am using like principle theme for My App "Theme.AppCompat" so when I try to custom the style for each of theme I always get a crash saying:
This component requires that you specify a valid TextAppearance attribute. Update your app theme to inherit from Theme.MaterialComponents (or a descendant).
How should I proceed?
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.
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'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