首页 > 解决方案 > 修复错误“根元素绘制背景”后,为什么图像在其他视图中重复?

问题描述

修复“可能的透支:根元素绘制背景”错误后,我的启动活动中出现了新问题;背景中设置的图像在进度条背景中重复

这是我的manifiest.xml代码

<activity
            android:name="com.dictionary.SplashActivity"
            android:launchMode="singleTask"
            android:screenOrientation="unspecified"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

splash.xml 代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:layout_marginEnd="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginBottom="18dp"
        android:theme="@style/BrownColor" />

</RelativeLayout>

和java代码

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.three_splash);}

样式.xml

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="AppTheme.NoActionBar">
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:background">@drawable/splash</item>
 </style>

 <style name="BrownColor" parent="ThemeOverlay.AppCompat.Light">
        <item name="colorAccent">#8e2308</item>
 </style>

和截图 在此处输入图像描述

标签: androidandroid-activityandroid-stylesappcompatactivity

解决方案


很简单,您正在为活动样式设置背景,这意味着您正在为其中的所有视图设置该背景。只需删除该行

<item name="android:background">@drawable/splash</item>

如果您正在创建启动画面 - 请改用 windowBackground


推荐阅读