In this video we will learn how to create a custom button that uses image files to replace the background of the default Android button.
For this we will create a StateListDrawable xml file, where we define appropriate png files from the drawable folder for the different button state combinations of state_pressed and state_enabled. We put these states as items between a selector tag to create a state list and set it as the background on our Button widget.
Just like for any other button, we can set an OnClickListener on our custom button, disable it etc.
Example code + button image files:
____________________
❗ Subscribe to the channel:
⏯ Watch more tutorials:
⭐ Become a channel member for exclusive tutorials and other perks:
㊙ Help translating the videos:
💚 Support the content:
💬 Join the Discord chat:
🎧 Audiobooks and podcasts for programmers:
👶 How to get started with Android development:
📣 Follow Coding in Flow on social media:
Facebook:
Instagram:
Twitter:
Blog:
Nguồn:https://wijstaanvooronzegrondrechten.org/
Subscribed 🙂 Love your accent, which is from where? Austria?
Hi where did you find png files for your buttons?
Hello. I like your way of explanation! But it didn't help me, if I add an image into the /drawable the picture appears there, but I can't use it in the code(there is no option for it). Can you help me with it? Thank you!
Nice tutorial with nice explanation tnx sir
thx a lot m8 im using this for my school project
I have a question. I've got a problem when I try to check onClickListener the button that is on another layout. My button is on the FrameLayout that change by navigation bar. And when I started my application, it always crashed by runtime error. (it seems myMainActivity cannot find the button from another Layout)
Great video! Very helpful to have those pop ups for button presses!
How do you get rid of the white square surrounding the image? I would like to use a black background with the button
Fantastic, but errors below, any clues? (running on AndroidStudio,3.4.2, using emulator Nexus5X):
error: package android.support.v7.app does not exist
error: cannot find symbol class AppCompatActivity
error: method does not override or implement a method from a supertype
error: cannot find symbol variable super
error: package R does not exist
error: package R does not exist
error: package R does not exist
error: no suitable method found for makeText(MainActivity,String,int)
method Toast.makeText(Context,CharSequence,int) is not applicable
(argument mismatch; MainActivity cannot be converted to Context)
method Toast.makeText(Context,int,int) is not applicable
(argument mismatch; MainActivity cannot be converted to Context)
@codinginflow Can u pl share the website where u got the images from? Thanks a lot for the tutorial.
la aplicación se ha detenido :'(
Your videos are so good! keep up the good work!
Can you tell us how you have created these buttons? I mean which software?
Thanks for the source code and images on your site.
thanku:)
hi, thanks for this good and short tutorial.
i have problem, after do all my new activity doesn't open and app crash!
what should i do?
I need a video with Kotlin now
German 😀
Can i add this buttom a sound like alarm?
Great explaination bro ❤️❣️✌
thanks so much for your helpful videos , i'm really appreciate your effort
please if i need to make a counter i mean with every click the text change with +1 , should i use a button with increment numbers or is there a better way? thanks in advance 🙂
How can I put a time slot in?
MAGNIFICENT
What is the website where you found these buttons?
You are the best!!!
I want to put two icons unchecked and checked radio button i know how to create drawable file in xml what next how to check it in java? Can i get the idea please asap!
can we run the program while editing?
Thanks!
Hey, ich habe das 1 zu 1 kopiert und bei mir funktioniert es nicht, ich habe ein Videos stumm geschaltet, hast du was wichtiges dazu gesagt?
Btw. ich finde super, das du im Video an den Code ranzoomst
Hi, I follow your channel. I'm an android studio student and I think he's an excellent teacher.
I liked this lesson with the buttons. Is that I am trying to develop an application where the user clicks the button and it changes the color, however, the button must remain with the color clicked until the user comes back and click the button again. That is, the button should remain with the color chosen by the user even if he closes the application.
Is it possible to do in android studio as well as html5 and css3?
PS: The application has to do the things I mentioned above online, so that other users interact
you are the best! brief and to the point!
Thanks bro, but in my case it doesn't display the button after changing from default_button to custom_button as in 6:45. Thanks
Nice explanation!
wonderful, thks
Wow bro. Thankyou for this tutorial
Would You be interested to work with me on an application? If so send me a PrivateMessage about your requirements in order to do so 🙂 Awesome Tutorial!! have a great Day!!
how to make a button like onclick on and onclick off
Thank you so much.. You are doing great.Really appreciate it
A good teacher. Thank you a sir.
do you have an app on google play ? i want to look at that.
we should give money fr playstore
bro how much we should invest to upload our app to playstore
I've just started with android studio and this channel served me very well thank you master thank you
Thanks bro i was finding this.. but if i have a vector asset(XML file button) then what to do for different states… i did the same as you but my app crashed
Dear sir,
Can you make video tutorial on android app licensing for paid app ? If possible please make the tutorial fast, it's very urgent & important to me.
Thank you.
You can make a video about ads