Home > Software engineering >  How to make Button like this in android studio
How to make Button like this in android studio

Time:09-24

How to make button like this in with android stdio

button

CodePudding user response:

Copy the below code and remove unwanted things

XML

<Button
    android:id="@ id/btn_submit"
   `enter code here` android:layout_below="@id/CV_mobile"
    style="@style/AnyButtonViewStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_marginTop="@dimen/_80sdp"
    android:layout_marginRight="@dimen/_40sdp"
    android:layout_marginLeft="@dimen/_40sdp"
    android:layout_marginBottom="@dimen/_10sdp"
    android:backgroundTint="@color/primary"
    android:gravity="center"
    android:paddingLeft="@dimen/_15sdp"
    android:paddingTop="@dimen/_10sdp"
    android:paddingRight="@dimen/_15sdp"
    android:paddingBottom="@dimen/_10sdp"
    android:text="CONTINUE"
    android:textColor="@color/white" />

STYLE

 <style name="AnyButtonViewStyle">


    <item name="android:textSize">16sp</item>
    <item name="android:imeOptions">actionDone</item>
    <item name="android:minWidth">@dimen/x60dp</item>
    <item name="android:textAllCaps">false</item>
    <item name="android:textStyle">normal</item>
    <item name="android:paddingLeft">@dimen/x16dp</item>
    <item name="android:paddingRight">@dimen/x16dp</item>
    <item name="android:foreground">@drawable/ripple_drawable</item>
    <item name="android:background">@drawable/round_button_selected</item>
    <item name="android:textColor">@color/white</item>
    <item name="backgroundTint">@color/colorPrimary</item>

</style>

DRAWABLE

    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#808285"/>
    <stroke android:width="3dip" android:color="#808285" />
    <corners android:radius="20dp"/>
    <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

CodePudding user response:

Make a button as per a picture you have to implement this below following steps.

  1. Right click on drawable
  2. Click on New
  3. Create new drawable resource file
  4. Enter file name.

After this enter below code.

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners  android:radius="50dp"/>
    // If you want to change shape than change the radius 50dp to 100dp
    <solid android:color="@color/purple"></solid>
    // If you change your background color then change color purple to another color
</shape>

And to use in your activity just like below

<Button
    android:id="@ id/btn_login"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dip"
    android:background="@drawable/rounded_corner"
    // After drawable/ use your file name where above code is pasted 

    android:text="@string/btn_login"
    android:textSize="20dp"
    android:textColor="@android:color/white" />

You can use this shape in all view like TextView, EditText, Button and etc.

  • Related