简体   繁体   中英

how to set drawable background of edit text programmatically

Hello every one I am new in the android studio I have a picture in my drawable folder and I want it to save the picture as a background of the edit text programmatically for this I write a code bellow but its not working and it showing a red line error

here is my code.

edit_text.setBackground(R.drawable.background1);

any idea for this how I will write it please don't suggest me another post as I am new here.

You should retrieve the background drawable using ContextCompat.getDrawable method:

edit_text.setBackground(ContextCompat.getDrawable(this, R.drawable.background1));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM