android studio image button,kotlin - image for button in android studio - Stack Overflow

This is my button class implementation:

package com.example.myproject

import android.R

import android.content.Context

import android.graphics.Color

import android.os.CountDownTimer

import android.util.Log

import android.widget.ImageView

import kotlin.properties.Delegates

data class MyButton() : androidx.appcompat.widget.AppCompatButton(context) {

init {

this.text = "test"

this.setOnClickListener { v ->

Log.d("CLICK", "click")

}

object: CountDownTimer(_time, 1000) {

override fun onTick(millisUntilFinished: Long) {

var rnd = (0..20).random()

if (rnd < 10) {

this.setBackgroundResource(R.drawable.notebook) //notebook

} else {

this.setBackgroundResource(R.drawable.desktop_pc) //desktop PC

}

}

override fun onFinish() {

exitProcess(-1)

}

}.start()

}

}

So I want to, based on some random generator, put whether notebook image or desktop PC image on my button. This is my res folder:

res > drawable > notebook.png, desktop_pc.png

Both images I put there using copy-paste. But the problem is that the method R.drawable cannot find these two files, it's not possible to load them from this folder. Where is the problem?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值