How to Add Custom Button to Android App - Android Studio 2.2.2 Tutorial

Custom Button can enhance user interface to your app! This time we're adding one to our app. Watch the entire video to understand it or go manual.



Button.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:drawable="@drawable/btpressed"
        android:state_pressed="true"/>
    <item
        android:state_focused="true"
        android:drawable="@drawable/bt"/>
    <item
        android:drawable="@drawable/bt"/>


</selector>

We uses two images of buttons, you can create them manually using Photoshop or any other tools.

activity_main.xml

    <Button
        android:background="@drawable/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/button2" />

We had shown the background for the button as button.xml that we created.


Hope that was a helpful tutorial for you!
Thanks!

1 comment:

  1. Nice blog........ thanks for this...... App In Minute provides you the platform that you seek for creating your online store. With App In Minute’s help, you can develop your Android Application & Website for free and display your products or services to the world. App in minute can create a free business portfolio app or a gallery app with App In Minute Tool. For more information visit on https://www.appinminute.com/

    ReplyDelete

Powered by Blogger.