Showing boundary around android-button - android

How can i achieve this scenario:
My android button tag in xml file:
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="100dp"
android:layout_height="10dp"
android:text="Select Plan"
android:id="#+id/button"
android:background="#ffffff"
android:textColor="#2D74B9"
android:layout_below="#+id/textView9"
android:layout_alignEnd="#+id/textView10"
android:layout_alignBottom="#+id/textView6"
android:layout_alignParentEnd="true"
android:clickable="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Plan"
android:padding="10dip"
android:id="#+id/button"
android:background="#drawable/border"
android:textColor="#2D74B9"
android:clickable="true" />
and
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dip"
android:color="#2D74B9" />
<corners android:radius="10dip"/>
<solid android:color="#android:color/transparent" />
</shape>

This will be your button xml
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="100dp"
android:layout_height="10dp"
android:text="Select Plan"
android:id="#+id/button"
android:background="#drawable/borderButton"
android:textColor="#2D74B9"
android:layout_below="#+id/textView9"
android:layout_alignEnd="#+id/textView10"
android:layout_alignBottom="#+id/textView6"
android:layout_alignParentEnd="true"
android:clickable="true" />
And this will be your borderButton.xml file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dip"
android:color="#2D74B9" />
<corners android:radius="10dip"/>
<solid android:color="#android:color/transparent" />

Create the following xml file under drawable folder let say abc.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="16dp"/>
<stroke
android:color="#000000"
android:width="3dp"
/>
</shape>
And,use it in your button background.
<Button
android:background="#drawable/abc"/>

Related

Button border is not appearing using drawable in android

I am using this code for adding a border to my button layout but no change is appearing in the button.
button_bg.xml(drawable)
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners
android:radius="14dp"
/>
<solid
android:color="#fff"
/>
<stroke
android:width="3px"
android:color="#000"
/>
</shape>
Layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="#+id/btnName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/button_bg"
android:textColor="#000"
android:text="#string/category_name" />
</RelativeLayout>

How to make drawable circle shape with count

I really appreciate if someone can help me with using how to drawable circle view with count as like my below image.
I wrote some code for my requirement but it's showing rectangular shape but i want circular shape..
linear_layout_border(drawable file)
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dp"
android:color="#color/colorPrimary" />
<solid android:color="#color/colorLightSky" />
<padding
android:bottom="2dp"
android:left="10dp"
android:right="10dp"
android:top="2dp" />
</shape>
xml:
<FrameLayout
android:id="#+id/group_attachment_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="3dp"
android:background="#drawable/linear_layout_border">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="#drawable/ic_group"
android:tint="#color/rosecolor" />
</RelativeLayout>
<TextView
android:id="#+id/members_count_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:layout_marginBottom="3dp"
android:background="#drawable/test_circle"
android:gravity="center"
android:minWidth="15dp"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:text="0"
android:textColor="#fff"
android:textStyle="bold"
android:visibility="visible" />
</FrameLayout>
image:-
Try this it looks as you want
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<corners
android:radius="10dip"/>
<solid
android:color="#2196F3" />
<stroke
android:width="2dip"
android:color="#FFF" />
<padding
android:left="2dip"
android:right="2dip"
android:top="2dip"
android:bottom="2dip" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#666666"/>
<size
android:width="120dp"
android:height="120dp"/>
</shape>
Use this code to draw a circle and put it as background of your TextView and make its android:gravity="center"
Change height and width according to your need.
Try following drawable
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item xmlns:android="http://schemas.android.com/apk/res/android">
<shape>
<solid android:color="#58050505" />
<corners
android:topLeftRadius="3dp"
android:topRightRadius="3dp"
android:bottomLeftRadius="3dp"
android:bottomRightRadius="3dp"
/>
</shape>
</item>
</selector>
Use this for the TextView background
inside drawable folder
badge_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:endColor="#color/purple"
android:startColor="#color/purple"></gradient>
<corners android:radius="100dp"></corners>
<stroke
android:width="0.5dp"
android:color="#color/white" />
</shape>
The TextView
<TextView
android:id="#+id/serial_no"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_gravity="top|start"
android:layout_marginTop="5dp"
android:background="#drawable/badge_background"
android:gravity="center|center_vertical"
android:maxLines="1"
android:text="1"
android:textColor="#android:color/white"
android:textSize="13sp"
android:textStyle="bold" />

How to create square button in android for background?

img
I want to create square shape in background. Android studio shape doesn,t support square.How to create manually in border.xml?
Here is my code
border.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#9294a3" />
<stroke
android:width="2dp"
android:color="#c2bbbb" />
<corners android:radius="2dp" />
</shape>
my.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#9294a3">
<TextView
android:id="#+id/tv_2"
android:layout_width="wrap_content"
android:text="2"
android:textColor="#c2bbbb"
android:textSize="30sp"
android:background="#drawable/border"
android:layout_height="wrap_content" />
</LinearLayout
Button like this
xml
<TextView
android:layout_width="150dp"
android:layout_height="150dp"
android:background="#drawable/border"
android:text="2"
android:textSize="50sp"
android:gravity="center"
android:textColor="#ffffff"
android:padding="5dp"/>
Style (drawable/border.xml)
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#color/colorGray"/>
<stroke android:color="#color/colorBlack"
android:width="4dp" />
<!--corners allow us to make the rounded corners button-->
<corners android:radius="15dp" />
</shape>
</item>
</selector>
<TextView
android:id="#+id/input_name"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="right"
android:direction="center"
android:gravity="center"/>
you should specify shape='Rectangle' for square it will be better.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle" >
<solid android:color="#9294a3" />
<stroke
android:width="2dp"
android:color="#c2bbbb" />
<corners android:radius="2dp" />

Style a EditText android

How to style a EditText like below image.
I tried different option but cant achieve that.
Image
<EditText
android:layout_width="300dp"
android:layout_height="40dp"
android:hint=" Name*"
android:background="#drawable/border"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
create a xml in drawble folder add this in it
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffff" />
<stroke android:width="1dip" android:color="#363534" />
<corners android:radius="5dp" />
</shape>
<LinearLayout
android:layout_width="match_parent"
android:layout_margin="10dp"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/round_corner"
android:padding="10dp"
android:hint="First Name *"
android:textColorHint="#a9a9b3"
android:textSize="18dp"
/>
</LinearLayout>
then create a drawable file for the round corner background
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<stroke android:width="2dip" android:color="#b0b6bc" />
<corners android:radius="3dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip"
android:bottom="0dip" />
</shape>
output image

Adding icon next to button text in android

I used this button generator. http://angrytools.com/android/button/
Is there an easy way to add an icon to the left of the text.
The drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="10dp"
/>
<gradient
android:angle="90"
android:startColor="#cacaca"
android:endColor="#FBFBFB"
android:type="linear"
/>
<padding
android:left="50dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="600dp"
android:height="60dp"
/>
<stroke
android:width="2dp"
android:color="#9f9f9f"
/>
</shape>
The button
<Button
android:id="#+id/angry_btn"
android:text="button"
android:textColor="#000000"
android:textSize="18sp"
android:layout_width="600dp"
android:layout_height="60dp"
android:background="#drawable/buttonshape"
android:shadowColor="#A4A4A4"
android:shadowDx="2"
android:shadowDy="3"
android:shadowRadius="5"
/>
Use android:drawableLeft attribute in the Button XML.
use 'android:drawableLeft="#drawable/userImage"' or 'android:drawableRight="#drawable/user_image"' in Button xml attribute
Try this wount really fail
<Button
android:id="#+id/fab"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#color/btn_registration_login"
android:text="LOGIN"
android:paddingLeft="125dp"
android:paddingRight="125dp"
android:textColor="#color/white"
android:drawableRight="#drawable/ic_navigate_next_white_18dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>

Categories

Resources