How to create transparent rounded button in android? [duplicate] - android

This question already has answers here:
How to make a round button?
(23 answers)
Closed 6 years ago.
I want to create button login and sign up like
.

Include the button.xml in your layout and use it as a button by giving it an id or u can set the border to button too in order to get the same result
button.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/border">
<TextView android:id="#+id/skillTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cleaner"
android:textSize="#dimen/abc_text_size_medium_material"
android:textColor="#color/text_grey"
android:layout_margin="#dimen/normal_margin"
android:layout_centerInParent="true"
/>
</RelativeLayout>
drawable/border.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="5dp"
/>
<stroke
android:width="1dp"
android:color="#color/white" />
</shape>

Related

Rounding the corners of a View in Kotlin [duplicate]

This question already has answers here:
How do I create a ListView with rounded corners in Android?
(11 answers)
Closed 2 years ago.
I have this View in Kotlin:
<View
android:id="#+id/DotView"
android:layout_width="6.5dp"
android:layout_height="6.5dp"
android:layout_marginBottom="10dp"
android:layout_gravity="bottom|center_horizontal"
android:background="#color/colorPrimary"
/>
and I need to round the corners since it is a Dot and I have been investigating and testing how I can do it to round the corners but I just can't find the answer.
How can I solve it?
you have to create a drawable shape xml file and set background property of the view to the drawable file!
res/drawable/circle.xml :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="#color/colorPrimary" />
</shape>
res/drawable/rounded.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/colorPrimary"/>
<corners android:radius="5dp" />
</shape>
and set background to view like this :
<View
android:id="#+id/DotView"
android:layout_width="6.5dp"
android:layout_height="6.5dp"
android:layout_marginBottom="10dp"
android:layout_gravity="bottom|center_horizontal"
android:background="#drawable/rounded"
/>

Imageview with rounded corner using kotlin [duplicate]

This question already has answers here:
How to make an ImageView with rounded corners?
(58 answers)
Closed 4 years ago.
I have created the layout with Imageview and I have set custom background with corner radius, the parent layout is cornered but the Imageview is not rounded cornered. How can I achieve this?
Thanks in advance.
bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<solid
android:color="#color/list_item_bg"/>
<stroke
android:width="2dp"
android:color="#color/colorAccent" />
<corners
android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
</shape>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/list_item_bg"
>
<ImageView
android:id="#+id/food_image"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:scaleType="centerCrop"
android:clipToOutline="true"
android:background="#drawable/image_bg"
android:src="#drawable/sample_image"/>
</LinearLayout>
Create res/drawable/round_outline.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp" />
</shape>
Set the drawable as your ImageView's background
android:background="#drawable/round_outline"
On ImageView (layout)
android:clipToOutline="true"

Custom UI for button and edittext

I have been trying to design a button and a edittext in native android but unable to create the exact UI as shown in the picture. If anyone has any idea how can I create such UI please share your thoughts. In the image the first field should act as an input box and the second field should act as button.
The following given xmls will create the same UI you asked for. :)
create roundedbutton.xml resource file in drawable folder, given below
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#eeC4C6C7" />
<corners android:bottomRightRadius="30dp"
android:bottomLeftRadius="30dp"
android:topRightRadius="30dp"
android:topLeftRadius="30dp"/>
</shape>
create roundededittext.xml resource file in drawable folder, given below
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#eeCD3E22" />
<corners android:bottomRightRadius="30dp"
android:bottomLeftRadius="30dp"
android:topRightRadius="30dp"
android:topLeftRadius="30dp"/>
</shape>
Create your main xml layout file. I created with your custom edit text, shown here:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp">
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/roundedbutton"
android:elevation="10dp"
android:layout_gravity="center_vertical"
android:text="t"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginLeft="-30dp"
android:elevation="2dp"
android:layout_gravity="center_vertical"
android:background="#drawable/roundededittext"/>
</LinearLayout>
Hope it helps! Ask for any doubt.

how to create a circular imageButton in android? [duplicate]

This question already has answers here:
Custom circle button
(11 answers)
Closed 8 years ago.
Guys i have created a imageButton in my layout file and set a circular png image as its background.but when i am running my application, its displaying me a square button with my given image placed in the middle of it.
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/sliderr" />
add android:background="#null"
Make a new shape XML in res/drawable/round_button.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<gradient
android:startColor="#FFFF0000"
android:endColor="#80FF00FF"
android:angle="270" />
</shape>
Use this shape as the button's background:
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#drawable/round_button"
android:src="#drawable/sliderr" />
You may also want to add android:scaleType="fitCenter" to your button to make the image the same size as the button, and android:adjustViewBounds="true" if your image has unequal height/width.
try to add this xml..
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#eeffffff" />
<corners android:bottomRightRadius="8dip"
android:bottomLeftRadius="8dip"
android:topRightRadius="8dip"
android:topLeftRadius="8dip"/>
</shape>

How to add border to button in android [duplicate]

This question already has answers here:
Android - border for button
(11 answers)
Closed 2 years ago.
Hi I'm covering my ImageView in buttons but while they are so close to each other you cant make out that it is buttons, its just a big red square. I need a quick and easy way to give my buttons borders/edges or something so you can see the different buttons.
Create a Shape in Drawable Resource
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#C0213A" />`<!--Background Color-->`
<stroke android:width="2dip" android:color="#C0213A"/> `<!--Border-->`
</shape>
In your XML
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp"
android:background="#drawable/your_shape"> `<!--This is your shape created--`>
There is no border for buttons but you can use shape to make a drawable with border then put it as background for the button.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#color/red" />
<stroke
android:width="1dp"
android:color="#color/black" />
</shape>

Categories

Resources