第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

應(yīng)用 setBackground() 錯(cuò)誤: 不兼容的類(lèi)型: int 無(wú)法轉(zhuǎn)換為可繪制

應(yīng)用 setBackground() 錯(cuò)誤: 不兼容的類(lèi)型: int 無(wú)法轉(zhuǎn)換為可繪制

慕無(wú)忌1623718 2022-09-14 16:08:46
在一個(gè)非常簡(jiǎn)單的應(yīng)用程序上工作,在單擊按鈕時(shí)更改背景顏色,我陷入了一個(gè)錯(cuò)誤,其中背景的顏色無(wú)法使用MainActivity.java文件進(jìn)行更改。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>在“主頁(yè)活動(dòng).java文件中設(shè)置背景時(shí),會(huì)彈出以下錯(cuò)誤,以顯示線條視圖。錯(cuò)誤:不兼容的類(lèi)型:int 無(wú)法轉(zhuǎn)換為可繪制我應(yīng)該怎么做才能解決此錯(cuò)誤?
查看完整描述

3 回答

?
慕蓋茨4494581

TA貢獻(xiàn)1850條經(jīng)驗(yàn) 獲得超11個(gè)贊

它可能應(yīng)該是view.setBackgroundResource(R.color.colorAccent);



查看完整回答
反對(duì) 回復(fù) 2022-09-14
?
Smart貓小萌

TA貢獻(xiàn)1911條經(jīng)驗(yàn) 獲得超7個(gè)贊

使用安卓X,您必須使用而不是yourContext.getResources().getColor(R.color.yourColor)(R.color.yourColor)



查看完整回答
反對(duì) 回復(fù) 2022-09-14
?
汪汪一只貓

TA貢獻(xiàn)1898條經(jīng)驗(yàn) 獲得超8個(gè)贊

與應(yīng)用程序兼容性活動(dòng)一起使用:

view.setBackground(ContextCompat.getDrawable(context, R.color.colorAccent));

view.setBackgroundColor(ContextCompat.getColor(context, R.color.colorAccent));


查看完整回答
反對(duì) 回復(fù) 2022-09-14
  • 3 回答
  • 0 關(guān)注
  • 246 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)