在一個非常簡單的應用程序上工作,在單擊按鈕時更改背景顏色,我陷入了一個錯誤,其中背景的顏色無法使用MainActivity.java文件進行更改。package com.example.audio;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;public class MainActivity extends AppCompatActivity { View view; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); view = this.getWindow().getDecorView(); view.setBackground(R.color.colorAccent); }}顏色.xml<?xml version="1.0" encoding="utf-8"?><resources> <color name="colorPrimary">#008577</color> <color name="colorPrimaryDark">#00574B</color> <color name="colorAccent">#D81B60</color></resources>activity_main.xml<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout 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" tools:context=".MainActivity"> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginLeft="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:layout_marginRight="8dp" android:layout_marginBottom="8dp" android:text="Button" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /></android.support.constraint.ConstraintLayout>在“主頁活動.java文件中設置背景時,會彈出以下錯誤,以顯示線條視圖。錯誤:不兼容的類型:int 無法轉換為可繪制我應該怎么做才能解決此錯誤?
應用 setBackground() 錯誤: 不兼容的類型: int 無法轉換為可繪制
慕無忌1623718
2022-09-14 16:08:46