Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 添加材质设计时,布局预览不显示布局_Android_Xml_Android Studio_Material Design - Fatal编程技术网

Android 添加材质设计时,布局预览不显示布局

Android 添加材质设计时,布局预览不显示布局,android,xml,android-studio,material-design,Android,Xml,Android Studio,Material Design,我正在开发一个Android应用程序。在我决定在主题中使用材料设计之前,一切似乎都很完美。添加材质设计主题后,版面预览不会显示预览,但在手机上构建时效果会非常好。当删除xml中使用的材质设计组件时,一切都可以完美地工作 附上我的代码: 活动\u home.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res

我正在开发一个Android应用程序。在我决定在主题中使用材料设计之前,一切似乎都很完美。添加材质设计主题后,版面预览不会显示预览,但在手机上构建时效果会非常好。当删除xml中使用的材质设计组件时,一切都可以完美地工作

附上我的代码:

活动\u home.xml

     <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/background"
        tools:context=".home.Home">


        <com.google.android.material.button.MaterialButton
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_centerInParent="true"
            android:id="@+id/logout"
            android:text="LOG OUT"
            />
    </RelativeLayout>
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- 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="AppTextField" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">

        <item name="boxBackgroundColor">@color/background</item>
        <item name="boxStrokeColor">@android:color/white</item>
        <item name="hintTextColor">@android:color/white</item>


    </style>




</resources>
build.graple(应用程序模块)

build.gradle(Prepup)

styles.xml

     <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/background"
        tools:context=".home.Home">


        <com.google.android.material.button.MaterialButton
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_centerInParent="true"
            android:id="@+id/logout"
            android:text="LOG OUT"
            />
    </RelativeLayout>
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- 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="AppTextField" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">

        <item name="boxBackgroundColor">@color/background</item>
        <item name="boxStrokeColor">@android:color/white</item>
        <item name="hintTextColor">@android:color/white</item>


    </style>




</resources>

@颜色/原色
@颜色/原色暗
@颜色/颜色重音
@颜色/背景
@android:彩色/白色
@android:彩色/白色
主要发生在布局预览中的错误

java.lang.IllegalArgumentException:java.lang。ClassCastException@b83d5b8 位于sun.reflect.GeneratedMethodAccessor509.invoke(未知源) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中 位于java.lang.reflect.Method.invoke(Method.java:498) 在android.animation.PropertyValuesHolder_Delegate.callMethod(PropertyValuesHolder_Delegate.java:108) 在android.animation.PropertyValuesHolder_Delegate.nCallFloatMethod(PropertyValuesHolder_Delegate.java:143)中 在android.animation.PropertyValuesHolder.nCallFloatMethod(PropertyValuesHolder.java)中 在android.animation.PropertyValuesHolder.access$400(PropertyValuesHolder.java:38) 位于android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:1387) 位于android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:990) 位于android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:674) 位于android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:637) 位于android.animation.ValueAnimator.start(ValueAnimator.java:1069) 在android.animation.ValueAnimator.start(ValueAnimator.java:1088) 位于android.animation.ObjectAnimator.start(ObjectAnimator.java:852) 在android.animation.ValueAnimator.startWithoutPulsing(ValueAnimator.java:1081)中 在android.animation.AnimatorSet.handleAnimationEvents(AnimatorSet.java:1142)上 在android.animation.AnimatorSet.startAnimation(AnimatorSet.java:1227)上 位于android.animation.AnimatorSet.start(AnimatorSet.java:729) 位于android.animation.AnimatorSet.start(AnimatorSet.java:684) 位于android.animation.StateListAnimator.start(StateListAnimator.java:188) 位于android.animation.StateListAnimator.setState(StateListAnimator.java:181) 在android.view.view.drawableStateChanged(view.java:21105) 位于android.widget.TextView.drawableStateChanged(TextView.java:5283) 位于androidx.appcompat.widget.AppCompatButton.drawableStateChanged(AppCompatButton.java:156) 位于android.view.view.refreshDrawableState(view.java:21160) 在android.view.view.dispatchAttachedToWindow(view.java:18379) 在android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404) 在android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404) 在android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404) 在android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3404) 在android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:42)中 在com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:335)上 位于com.android.layoutlib.bridge.bridge.createSession(bridge.java:391) 位于com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:195) 位于com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:540) 在com.android.tools.idea.rendering.RenderTask.lambda$inflate$5(RenderTask.java:666) 位于java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590) 位于java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 位于java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 运行(Thread.java:745)

注意:应用程序在Moble上运行得很好,但是布局预览没有显示布局,这就是问题所在

提前感谢。

编辑 我已经做了以下的解决方案,但什么都没有发生,错误依然存在

  • 使缓存无效并重新启动
  • 干净利落
  • 将材质设计还原为1.0.0版

在以下更改后刷新布局:

1) 从文件活动\u home.xml的父布局中删除行
tools:context=“.home.home”

2) 将文件HomeActivity.java中的类名Home更改为HomeActivity

3) 与gradle文件重新同步项目

编辑:
这不是由于XML/后端代码中的错误造成的。这是由于Android Studio中的一个可以跟踪的bug,它显然在版本3.6 Canary 3(API 29和material_version='1.1.0-alpha08')中得到了修复。

您的Android Studio版本是什么?Android Studio版本3.4.2尝试从预览窗口更改应用主题。当我从设计屏幕更改应用主题时,它显示布局,但颜色显示不正确。另外,当我从设计模式切换到文本模式并打开侧面预览屏幕时,错误仍然存在,并且没有显示预览所有步骤,但仍然没有显示预览。
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- 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="AppTextField" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">

        <item name="boxBackgroundColor">@color/background</item>
        <item name="boxStrokeColor">@android:color/white</item>
        <item name="hintTextColor">@android:color/white</item>


    </style>




</resources>