Thursday, 26 June 2014

How to create standard Borderless buttons in Android??



Basically it can done in Two Steps:

Step1:
   Setting the button background attribute to android:attr/selectableItemBackground creates you a button with feedback but no background. SO you need to write like this(In xml):

   android:background="?android:attr/selectableItemBackground"

Step2: 
  The line to divide the borderless button from the rest of you layout is done by a view with the background android:attr/dividerVertical

   android:background="?android:attr/dividerVertical"


 Before applying logic your code will look like this in xml file:

 <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#ffffff"
        android:textStyle="bold"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:gravity="left|center_vertical"
        android:text="Button" />




<Button
        android:id="@+id/btn_home"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#ffffff"
        android:textStyle="bold"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:background="?android:attr/selectableItemBackground"
        android:gravity="left|center_vertical"

        android:text="Button" />

After applying above logic: