J'utilise MaterialCardView comme ma mise en page cardview
. Maintenant, Android-studio a commencé à me montrer qu'au lieu de l'actuel implementation "com.google.Android.material:material:1.0.0"
, Je devrais mettre à jour vers 1.1.0
<LinearLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
xmlns:app="http://schemas.Android.com/apk/res-auto"
Android:id="@+id/edit_name"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_gravity="center"
Android:orientation="vertical"
Android:layout_margin="@dimen/activity_vertical_margin">
<com.google.Android.material.card.MaterialCardView
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<...more layout>
</com.google.Android.material.card.MaterialCardView>
</LinearLayout>
avec 1.1.0, je reçois un crash Error inflating class com.google.Android.material.card.MaterialCardView
Donc, j'ai 3 cas:
1.0.0
et utilisez MaterialCardView
(fonctionne, mais pas de préférence)1.1.0
(ou 1.2.0-alpha) et utilisez androidx.CardView
(travail, mais pas préféré)1.1.0
et changez le MaterialCardView
(préféré, mais ne fonctionne pas)Puisque je veux utiliser l'option n ° 3 et que je n'ai pas de solution, est-ce que quelqu'un peut donner un indice?
Mise à jour Mon style (j'ai aussi style & style-night. Ici, je poste le style
uniquement):
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="ThemeOverlay.AppCompat.navTheme">
<!-- Color of text and icon when SELECTED -->
<item name="colorPrimary">#ffffff</item>
<!-- Background color when SELECTED -->
<item name="colorControlHighlight">@color/colorPrimary</item>
</style>
</resources>
Et voici l'erreur (de Logcat)
2020-02-12 13:34:18.171 12562-12562/com.example.phocast E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.phocast, PID: 12562
Android.view.InflateException: Binary XML file line #10 in com.example.phocast:layout/fragment_place: Binary XML file line #10 in com.example.phocast:layout/fragment_place: Error inflating class com.google.Android.material.card.MaterialCardView
Caused by: Android.view.InflateException: Binary XML file line #10 in com.example.phocast:layout/fragment_place: Error inflating class com.google.Android.material.card.MaterialCardView
Caused by: Java.lang.reflect.InvocationTargetException
at Java.lang.reflect.Constructor.newInstance0(Native Method)
at Java.lang.reflect.Constructor.newInstance(Constructor.Java:343)
at Android.view.LayoutInflater.createView(LayoutInflater.Java:854)
at Android.view.LayoutInflater.createViewFromTag(LayoutInflater.Java:1006)
at Android.view.LayoutInflater.createViewFromTag(LayoutInflater.Java:961)
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:1123)
at Android.view.LayoutInflater.rInflateChildren(LayoutInflater.Java:1084)
at Android.view.LayoutInflater.inflate(LayoutInflater.Java:682)
at Android.view.LayoutInflater.inflate(LayoutInflater.Java:534)
at Android.view.LayoutInflater.inflate(LayoutInflater.Java:481)
at com.example.phocast.MainActivity.onOptionsItemSelected(MainActivity.Java:555)
at Android.app.Activity.onMenuItemSelected(Activity.Java:4137)
at androidx.fragment.app.FragmentActivity.onMenuItemSelected(FragmentActivity.Java:383)
at androidx.appcompat.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.Java:219)
at androidx.appcompat.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.Java:109)
at androidx.appcompat.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.Java:109)
at androidx.appcompat.app.ToolbarActionBar$2.onMenuItemClick(ToolbarActionBar.Java:64)
at androidx.appcompat.widget.Toolbar$1.onMenuItemClick(Toolbar.Java:207)
at androidx.appcompat.widget.ActionMenuView$MenuBuilderCallback.onMenuItemSelected(ActionMenuView.Java:781)
at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.Java:840)
at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.Java:158)
at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.Java:991)
at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.Java:981)
at androidx.appcompat.widget.ActionMenuView.invokeItem(ActionMenuView.Java:625)
at androidx.appcompat.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.Java:151)
at Android.view.View.performClick(View.Java:7125)
at Android.view.View.performClickInternal(View.Java:7102)
at Android.view.View.access$3500(View.Java:801)
at Android.view.View$PerformClick.run(View.Java:27336)
at Android.os.Handler.handleCallback(Handler.Java:883)
at Android.os.Handler.dispatchMessage(Handler.Java:100)
at Android.os.Looper.loop(Looper.Java:214)
at Android.app.ActivityThread.main(ActivityThread.Java:7356)
at Java.lang.reflect.Method.invoke(Native Method)
at com.Android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.Java:492)
at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java:930)
Caused by: Java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
at com.google.Android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.Java:248)
at com.google.Android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.Java:222)
at com.google.Android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.Java:150)
at com.google.Android.material.internal.ThemeEnforcement.obtainStyledAttributes(ThemeEnforcement.Java:81)
at com.google.Android.material.card.MaterialCardView.<init>(MaterialCardView.Java:124)
at com.google.Android.material.card.MaterialCardView.<init>(MaterialCardView.Java:114)
at Java.lang.reflect.Constructor.newInstance0(Native Method)
at Java.lang.reflect.Constructor.newInstance(Constructor.Java:343)
at Android.view.LayoutInflater.createView(LayoutInflater.Java:854)
at Android.view.LayoutInflater.createViewFromTag(LayoutInflater.Java:1006)
at Android.view.LayoutInflater.createViewFromTag(LayoutInflater.Java:961)
at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:1123)
at Android.view.LayoutInflater.rInflateChildren(LayoutInflater.Java:1084)
at Android.view.LayoutInflater.inflate(LayoutInflater.Java:682)
at Android.view.LayoutInflater.inflate(LayoutInflater.Java:534)
at Android.view.LayoutInflater.inflate(LayoutInflater.Java:481)
at com.example.phocast.MainActivity.onOptionsItemSelected(MainActivity.Java:555)
at Android.app.Activity.onMenuItemSelected(Activity.Java:4137)
at androidx.fragment.app.FragmentActivity.onMenuItemSelected(FragmentActivity.Java:383)
at androidx.appcompat.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.Java:219)
at androidx.appcompat.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.Java:109)
at androidx.appcompat.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.Java:109)
at androidx.appcompat.app.ToolbarActionBar$2.onMenuItemClick(ToolbarActionBar.Java:64)
at androidx.appcompat.widget.Toolbar$1.onMenuItemClick(Toolbar.Java:207)
at androidx.appcompat.widget.ActionMenuView$MenuBuilderCallback.onMenuItemSelected(ActionMenuView.Java:781)
at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.Java:840)
at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.Java:158)
at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.Java:991)
at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.Java:981)
at androidx.appcompat.widget.ActionMenuView.invokeItem(ActionMenuView.Java:625)
at androidx.appcompat.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.Java:151)
at Android.view.View.performClick(View.Java:7125)
at Android.view.View.performClickInternal(View.Java:7102)
at Android.view.View.access$3500(View.Java:801)
at Android.view.View$PerformClick.run(View.Java:27336)
at Android.os.Handler.handleCallback(Handler.Java:883)
at Android.os.Handler.dispatchMessage(Handler.Java:100)
at Android.os.Looper.loop(Looper.Java:214)
at Android.app.ActivityThread.main(ActivityThread.Java:7356)
at Java.lang.reflect.Method.invoke(Native Method)
at com.Android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.Java:492)
at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java:930)
2020-02-12 13:34:18.620 12562-12584/com.example.phocast I/example.phocas: Background young concurrent copying GC freed 110384(4259KB) AllocSpace objects, 46(1212KB) LOS objects, 41% free, 7792KB/12MB, paused 1.092ms total 150.548ms
2020-02-12 13:34:18.692 12562-12562/com.example.phocast I/Process: Sending signal. PID: 12562 SIG: 9
Si après avoir changé le thème en Theme.MaterialComponents
dans le styles.xml n'a pas fonctionné alors assurez-vous d'avoir ajouté la balise style dans MaterialCard.
style="@style/Widget.MaterialComponents.CardView"