change colour of button in android

Change colour of button in Android Studio

As you know, the Default color of the button in the android studio is grey which is not suits for UI. So, here we are going to discuss how to change the colour of the button in android studio using different methods

Method 1: Using XML

First, add the button in XML layout like this

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GeeksToCode"
android:layout_gravity="center"
android:layout_marginTop="200dp"
/>
</LinearLayout>
change colour of button in android
Normal color of button

After this you will see your button looks something like this

Now you need to add another tag that is android:background=”color Hexa code” like this,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
   android:orientation="vertical"
    android:layout_height="match_parent">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="GeeksToCode"
        android:layout_gravity="center"
        android:background="#FF5722"      
        android:layout_marginTop="200dp"
        />
</LinearLayout>

Now, you see your button looks like this

change colour of button in android
coloured color of button

Method 2: Using a drawable file

This is my best method because it provides you many other operations to perform on the button like rounded corner etc.

Right click on drawable -> new-> drawable resource file and named as background.

Add following line of code there

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    >
    <stroke android:width="1dp" android:color="#FFC107" />
    <solid android:color="#FFC107"/>
</shape>

You see something like this

change colour of button in android
drawable file

Now, goto your button and drawable like this

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="GeeksToCode"
        android:layout_gravity="center"
        android:background="@drawable/rounded"
        android:layout_marginTop="200dp"
        />
change colour of button in android
coloured button

We update this content as we see more and more methods to change the colour of button in android studio.

How to add button in android studio?

Simply add from the design section of XML layout.

How to change the colour of button in android studio?

Add android:background=”colour” in button

Sudhanshu is Technology geek and also a pro pubg player. I like to create content in my free time that helps others. Currently pursuing BCA from Noida and operating Geekstocode

31 Comments

  1. Have you ever considered about including a little bit more than just your articles? I mean, what you say is valuable and everything. However think of if you added some great images or video clips to give your posts more, “pop”! Your content is excellent but with images and clips, this site could certainly be one of the most beneficial in its field. Fantastic blog!

  2. You made several fine points there. I did a search on the issue and found a good number of persons will consent with your blog.

  3. I’m really enjoying the design and layout of your website. It’s a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hire out a developer to create your theme? Superb work!

  4. I am really loving the theme/design of your blog. Do you ever run into any internet browser compatibility issues? A handful of my blog readers have complained about my website not working correctly in Explorer but looks great in Opera. Do you have any ideas to help fix this issue?

  5. I was curious if you ever considered changing the page layout of your site? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having 1 or 2 images. Maybe you could space it out better?

  6. Excellent website. Plenty of helpful info here. I am sending it to several buddies ans additionally sharing in delicious. And naturally, thank you for your effort!

  7. Youre so cool! I dont suppose Ive learn something like this before. So good to seek out somebody with some authentic thoughts on this subject. realy thanks for starting this up. this website is one thing that’s needed on the web, someone with a bit of originality. useful job for bringing something new to the web!

  8. Hey would you mind stating which blog platform you’re working with? I’m going to start my own blog soon but I’m having a hard time selecting between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I’m looking for something unique. P.S Apologies for getting off-topic but I had to ask!

  9. I was recommended this web site by my cousin. I am not sure whether this post is written by him as nobody else know such detailed about my difficulty. You are wonderful! Thanks!

  10. It’s perfect time to make some plans for the long run and it’s time to be happy. I’ve read this publish and if I could I want to counsel you some fascinating things or suggestions. Perhaps you can write next articles regarding this article. I wish to learn even more issues approximately it!

  11. Hi there, just became aware of your blog through Google, and found that it’s truly informative. I am gonna watch out for brussels. I will appreciate if you continue this in future. Lots of people will be benefited from your writing. Cheers!

  12. Hey very cool site!! Man .. Beautiful .. Amazing .. I will bookmark your web site and take the feeds also…I am happy to find a lot of useful information here in the post, we need work out more strategies in this regard, thanks for sharing. . . . . .

  13. wonderful post, very informative. I wonder why the other experts of this sector don’t notice this. You should continue your writing. I’m sure, you have a huge readers’ base already!

  14. Very great post. I simply stumbled upon your blog and wanted to say that I’ve really loved browsing your weblog posts. In any case I’ll be subscribing to your feed and I hope you write again very soon!

  15. I like the helpful info you supply on your articles. I will bookmark your weblog and test once more here frequently. I am fairly sure I’ll be informed a lot of new stuff right here! Best of luck for the following!

  16. Woah! I’m really loving the template/theme of this website. It’s simple, yet effective. A lot of times it’s challenging to get that “perfect balance” between usability and appearance. I must say you have done a excellent job with this. Also, the blog loads super quick for me on Opera. Outstanding Blog!

  17. I just wanted to develop a word so as to thank you for all the amazing hints you are posting at this website. My incredibly long internet search has at the end been honored with reliable facts and techniques to share with my friends and classmates. I would declare that most of us readers are undoubtedly endowed to exist in a very good site with very many outstanding individuals with useful guidelines. I feel really privileged to have used your entire website page and look forward to many more thrilling moments reading here. Thanks a lot once more for all the details.

  18. Hello this is somewhat of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding skills so I wanted to get advice from someone with experience. Any help would be greatly appreciated!

  19. Heya i am for the first time here. I came across this board and I find It really useful & it helped me out a lot. I hope to give something back and aid others like you helped me.

  20. It’s extremely difficult to locate experienced people for this particular topic, however, you appear to be do
    you know what you’re talking about! Thanks

    Here is my website … OnieYClerf

  21. I’m curious to find out what blog system you are utilizing? I’m having some minor security problems with my latest website and I would like to find something more risk-free. Do you have any suggestions?

  22. You made some clear points there. I looked on the internet for the subject and found most guys will approve with your blog.

  23. Sorry for the huge review, but I’m really loving the new Zune, and hope this, as well as the excellent reviews some other people have written, will help you decide if it’s the right choice for you.

  24. It’s a pity you don’t have a donate button! I’d without a doubt donate to this outstanding blog! I guess for now i’ll settle for bookmarking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this site with my Facebook group. Talk soon!

  25. You could certainly see your expertise in the work you write. The sector hopes for even more passionate writers such as you who aren’t afraid to mention how they believe. At all times go after your heart.

  26. Have you ever thought about creating an ebook or guest authoring on other websites? I have a blog centered on the same topics you discuss and would really like to have you share some stories/information. I know my readers would appreciate your work. If you’re even remotely interested, feel free to send me an e-mail.

  27. Normally I don’t read article on blogs, however I wish to say that this write-up very pressured me to take a look at and do it! Your writing taste has been amazed me. Thank you, very great article.

  28. Attractive section of content. I just stumbled upon your site and in accession capital to assert that I acquire actually enjoyed account your blog posts. Anyway I will be subscribing to your augment and even I achievement you access consistently fast.

  29. Thank you so much for giving everyone an exceptionally splendid possiblity to read critical reviews from here. It really is so fantastic and jam-packed with a good time for me and my office colleagues to visit your website at the very least three times in one week to learn the latest secrets you will have. And lastly, I’m so actually motivated with all the splendid solutions served by you. Some 1 ideas in this article are certainly the most efficient we’ve ever had.

Leave a Comment

Your email address will not be published. Required fields are marked *