膨胀类com.google.android.material.textfield.TextInputLayout时出错
这是我的应用程序主题:膨胀类com.google.android.material.textfield.TextInputLayout时出错,android,android-layout,kotlin,material-components-android,Android,Android Layout,Kotlin,Material Components Android,这是我的应用程序主题: 我得到了一个膨胀错误,原因是没有使用所需的主题。在Manifest中,我没有覆盖发生此错误的活动的主题,因此使用了style.xml中定义的AppTheme 错误: android.view.InflateException: Binary XML file line #122: Binary XML file line #122: Error inflating class com.google.android.material.textfield.TextInpu
我得到了一个膨胀错误,原因是没有使用所需的主题。在Manifest
中,我没有覆盖发生此错误的活动的主题,因此使用了style.xml
中定义的AppTheme
错误:
android.view.InflateException: Binary XML file line #122: Binary XML file line #122: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: android.view.InflateException: Binary XML file line #122: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
...
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
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:240)
at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:215)
at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:143)
at com.google.android.material.internal.ThemeEnforcement.obtainTintedStyledAttributes(ThemeEnforcement.java:116)
这是我的xml:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/inputFirstName"
style="@style/EditText.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="16dp"
android:visibility="gone"
app:boxStrokeColor="@color/colorBrand"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
舱单:
<application
android:name=".application.BaseApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
主题:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:fontFamily">@font/nunito_regular</item>
<item name="android:lineSpacingExtra">0dp</item>
<item name="android:includeFontPadding">false</item>
<item name="navigationIcon">@drawable/ic_back_dark</item>
<item name="android:windowBackground">@color/colorWhite</item>
<item name="bottomSheetDialogTheme">@style/AppBottomSheetDialogTheme</item>
</style>
@颜色/原色
@颜色/原色暗
@颜色/颜色重音
真的
@字体/nunito_常规
0dp
假的
@可抽出式/集成电路-背面-深色
@彩色/彩色白色
@样式/AppBottomSheetDialogTheme
我也面临同样的问题。
问题在于材料版本。
尝试更改您的alpha06版本,它会修复它
implementation 'com.google.android.material:material:1.1.0-alpha06'
在父布局中尝试应用此样式: android:theme=“@style/theme.MaterialComponents.DayNight.darkaActionBar”
我也面临同样的问题。下面是我如何解决它的。我实现了这个
implementation 'com.google.android.material:material:1.0.0'
然后我将样式从
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
到
启动FragmentIncontainer(themeResId=R.style.AppTheme)
在构造函数中添加主题 将android:theme=“theme.MaterialComponents”添加到布局中。不工作,出现相同消息崩溃请向我们展示您的设计参考在gradle中的外观。看起来你正在混合appcompat和androidx。请特别添加清单-应用程序主题的外观。@ror我已经添加了详细信息。可能是因为应用程序主题对不同的sdk版本有不同的表示,并且没有正确继承您测试的版本吗@ghitano,问题是textinput在一个对话框中,我用于对话框的上下文是活动上下文而不是片段上下文,打开对话框这并不能提供问题的答案。若要评论或要求作者澄清,请在其帖子下方留下评论。-这是我唯一要做的事。工作很有魅力,谢谢你@不客气,很高兴听到这对某人有所帮助。感谢分享解决方案。为我拯救生命。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="vertical"
android:theme="@style/Theme.MaterialComponents.DayNight.DarkActionBar">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
<com.google.android.material.textfield.TextInputEditText
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<style name="MyApp" parent="Theme.MaterialComponents">
implementation 'com.google.android.material:material:1.0.0'
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
launchFragmentInContainer<LoginFragment>(themeResId =R.style.AppTheme)