How to design EditText and Button in Android - android

How can I design my EditText and Button like in the Instagram application? I understand that I would need to do this by using Drawable files but every link I have found only shows how to design using Gradients which looks horrible. I just want something simple but not sure where to start.

All you need to do is create a Button or Edittext or TextView with transparent background and colored border like:
activity code :
<?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="match_parent"
android:background="#color/colorpink">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Transparent Button with blue border"
android:id="#+id/button"
android:padding="10dp"
android:layout_gravity="center_horizontal"
android:background="#drawable/transparent_button_selector"
android:textColor="#color/colorPrimary"
android:textAllCaps="false"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
transparent_button_selector.xml :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- pressed state -->
<item android:state_pressed="true"><shape>
<solid android:color="#android:color/transparent" />
<stroke android:width="2dp" android:color="#color/colorPrimary" />
<corners android:radius="22dp" />
</shape></item>
<!-- focused state -->
<item android:state_focused="true"><shape>
<solid android:color="#android:color/transparent" />
<stroke android:width="2dp" android:color="#color/colorPrimary" />
<corners android:radius="22dp" />
</shape></item>
<!-- normal state -->
<item><shape>
<solid android:color="#android:color/transparent"/>
<stroke android:width="2dp" android:color="#color/colorPrimary" />
<corners android:radius="22dp" />
</shape></item>
</selector>
colors :
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorpink">#AAFF4081</color>
And its looking like :
You can change transparent_button_selector.xml , change colors, radius values, borders and try to create your layout firstly and then think about background. Yes i will say gradient too . There is one question here for it : changing-gradient-background-colors-on-android-at-runtime
Also you can play with backgorund color, if you use few transparent white like #33FFFFFF then the result will be like : http://imgur.com/poGN2nn

It looks like they are using a single gradient drawable for the background of the login layout and then the EditTexts have a mostly-transparent white background and the Button has a fully transparent background. To round the corners of the EditText/Button, set the background to a drawable that looks something like this:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#android:color/transparent"/>
<corners
android:bottomRightRadius="2dp"
android:bottomLeftRadius="2dp"
android:topLeftRadius="2dp"
android:topRightRadius="2dp"/>
</shape>

may be this code can help you. This is the activity.xml file. use TextView as Button.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FF929999">
<EditText
android:id="#+id/userName"
android:layout_width="fill_parent"
android:layout_height="48.0dip"
android:layout_marginBottom="16.0dip"
android:background="#drawable/input_field"
android:hint="username"
android:inputType="textNoSuggestions"
android:paddingLeft="16.0dip"
android:paddingRight="16.0dip"
android:singleLine="true"
android:textColor="#color/white"
android:textColorHint="#b3ffffff"
android:textCursorDrawable="#null"/>
<TextView
android:id="#+id/saveButton"
android:layout_width="match_parent"
android:layout_height="48.0dip"
android:background="#drawable/button_border"
android:gravity="center"
android:text="Save"
android:textColor="#ccffffff"
android:textSize="16sp"
android:textStyle="bold"/>
</LinearLayout>
input_field.xml file should look like this:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#1affffff"/>
<corners android:radius="2.0dip"/>
</shape>
And button_border.xml will be like this:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#1affffff"/>
<stroke
android:width="1.0dip"
android:color="#80ffffff"/>
<corners android:radius="2.0dip"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#00000000"/>
<stroke
android:width="1.0dip"
android:color="#33ffffff"/>
<corners android:radius="2.0dip"/>
</shape>
</item>
enjoy the design.

Use Drawable with border and transparent color for EditText and Button, and the entire violet background is image, not gradient drawable. And also use TransitionDrawable for transitioning between two drawables like Instagram.

Related

Adding shadow to Rounded corner TextView?

I want to add shadow to my text view . I found solutions for adding gradients and one other solution which suggested creating a duplicate text view with a lighter shade at the back of the original textView to give a shadow effect. But i want to have a real shadow effect.
This is what i tried .I created an xml file rounded_corner.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
android:width="1dp"
android:color="#33000000"
android:dashWidth="3dp"
/>
<solid android:color="#000000" />
<padding
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<corners android:radius="10dp"
/>
</shape>
I added elevation and translationz but its not showing shadow in the output
<TextView
android:background="#drawable/rounded_corners"
android:layout_width="260dp"
android:layout_height="70dp"
android:textSize="50sp"
android:text="Welcome User"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:textColor="#000000"
android:elevation="50dp"
android:translationZ="10dp"
android:id="#+id/welcome"/>
I assume that you want to put the shadow on the TextView and not on the text itself. The you can make a layer-list inside your rounded corner drawable file like this:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#android:color/black" />
<corners android:radius="3dp" />
</shape>
</item>
<item android:bottom="2dp" android:right="2dp">
<shape android:shape="rectangle">
<solid android:color="#282828" />
<stroke android:width="1dp" android:color="#302f2f" />
</shape>
</item>
</layer-list>
If you put the drawable as background of your TextView
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/rounded_corner"
the output will link like this:
Just pu this on your TextView XML for shadow on the text:
android:shadowColor="#android:color/holo_purple"
android:shadowDx="10"
android:shadowDy="10"
android:shadowRadius="5"
you can edit with your preferences.
And create a Drawable file for shadow in all input, more or less like this one:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Bottom 2dp Shadow -->
<item>
<shape android:shape="rectangle" >
<solid android:color="#d8d8d8" />
</shape>
</item>
<!-- White Top color -->
<item android:bottom="4px" android:left="0px" android:right="4px" android:top="0px">
<shape android:shape="rectangle" >
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
You can use the shadow XML attributes.
android:shadowColor="#000"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="50"
For more info check this link, https://developer.android.com/reference/android/widget/TextView.html#attr_android:shadowColor

Spinner background make the title disappear

I have to implement in spinner the same background as in editText but when I put the property in spinner the title (sector1) and the arrow of disappears. how i can make it to appear?
Code xml of spinner and editText-->
<Spinner
android:id="#+id/registration_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/padding_horizontal_normal"
android:entries="#array/registration_sector"
android:paddingBottom="#dimen/padding_vertical_small"
android:paddingLeft="#dimen/appIntroDefaultPaddingLeft"
android:paddingTop="#dimen/padding_vertical_small"
android:textStyle="bold"/>
<EditText
android:id="#+id/registration_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/padding_horizontal_normal"
android:background="#drawable/edit_text_shape"
android:hint="#string/prompt_email"
android:inputType="textEmailAddress"
android:maxLength="16"
android:maxLines="1"
android:paddingBottom="#dimen/padding_vertical_small"
android:paddingLeft="#dimen/appIntroDefaultPaddingLeft"
android:paddingTop="#dimen/padding_vertical_small"
android:textStyle="bold"/>
Code of shape -->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dp"
android:color="#color/black"/>
</shape>
Image of editText and spinner -->
Try this as the background of spinner
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape>
<stroke android:width="1dp" android:color="#color/black" />
</shape>
</item>
<item>
<bitmap android:gravity="right|center" android:src="#drawable/your_spinner_arrow_image" />
</item>
</layer-list>
</item>
Arrow at spinner is part of background.
You should use ninepatch to create background of Spinner.
For example background of spinner for xxhdpi:
And my EditText background
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#android:color/transparent"/>
<stroke android:color="#color/colorSecondaryText" android:width="2px"/>
<corners android:radius="4dp"/>
</shape>

Android Custom Button Ripple/pulse Effect

I have created a custom circular button using the following :
<Button
android:id ="#+id/StartButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:background="#drawable/button_bg_round"
android:padding="15dp"
android:textSize="30sp"
android:textStyle="bold"
android:textColor="#ffffff"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
Here button_bg_round is defined as below :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<stroke android:color="#ffffff" android:width="5dp" />
<solid android:color="#3aeaee"/>
<size android:width="200dp" android:height="200dp"/>
</shape>
</item>
</selector>
Now, I want to add a circular ripple/pulse effect/animation when the button is clicked. I tried to look for a possible solution on google and SO but couldn't find any related to such a button. Any help would be much appreciated.
You can make you drawable like this:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#color/colorAccent"
tools:targetApi="lollipop"> <!-- ripple effect color -->
<item android:id="#android:id/background">
<shape android:shape="oval">
<stroke android:color="#ffffff" android:width="5dp" />
<solid android:color="#3aeaee"/>
<size android:width="200dp" android:height="200dp"/>
</shape>
</item>
</ripple>
where android:color inside ripple is the color of the effect.

How to make drawableshape in Android using xml?

I need to make the below shape using xml.
I have created an oval shape using below xml code.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is the line -->
<item android:height="400dp"><shape
android:shape="oval">
<solid android:color="#000000" />
</shape></item>
</layer-list>
But I am not able to draw a line and circle together. Please help me to make the above shape using 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/comment_background"/>
<stroke android:color="#color/gray" android:width="0.5dp"/>
</shape>
This is Code for Creating Circle shape in android
Finally I have come with a solution after little googling.
Followed steps:-
1.Created a xml file called dot.xml in drawable folder to draw a dot or filled circle.
//Dot.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/colorTimeline" />
</shape>
2.Inserted below code into layout file.
<View
android:id="#+id/v1"
android:layout_width="1dp"
android:layout_height="50dp"
android:background="#color/colorTimeline"
android:contentDescription="ad"
android:layout_marginStart="10dp"/>
<View
android:id="#+id/v2"
android:layout_width="16dp"
android:layout_height="16dp"
android:background="#drawable/dot"
android:contentDescription="f"
android:layout_marginStart="3dp"
android:layout_below="#id/v1"
android:layout_marginEnd="24dp"/>
<View
android:id="#+id/v3"
android:layout_width="1dp"
android:layout_height="50dp"
android:background="#color/colorTimeline"
android:contentDescription="ad"
android:layout_marginStart="10dp"
android:layout_below="#id/v2"/>
Final Output :-
Output Screenshot
My eyes bleeding, when i see your solution, sorry. I had to create and show you this one. Remember this example works only for known size of view. If you want to use dynamic values create my example drawable programatically.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- VERTICAL LINE -->
<item
android:left="9dp"
android:right="9dp">
<shape
android:shape="rectangle">
<solid
android:color="#FF0000" />
<size
android:width="2dp"
android:height="200dp" />
</shape>
</item>
<!-- OVAL -->
<item
android:top="90dp"
android:bottom="90dp">
<shape
android:shape="oval">
<solid
android:color="#FF0000" />
<size
android:width="20dp"
android:height="20dp" />
</shape>
</item>
</layer-list>
If you need any explanation just let me know.

Edit text with round corner and shadow

I am trying to achieve the effect which is shown in this following image:
In this image there is an edittext with round corner and internal shadow at top. I tried a lot but not success in getting shadow inside edittext.
I searched on this topic but all examples show shadow outside edittext border. I have no idea how can I achieve this.
The button and background image is already done, The only thing which is left is edittext shadow. If someone has already done this or know how to do this please share with me. Any help whould be appreciated.
Got like this
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:centerY="0.2"
android:startColor="#FFBDBDBD"
android:centerColor="#65FFFFFF"
android:endColor="#00FFFFFF"
android:angle="270"
/>
<stroke
android:width="1dp"
android:color="#C3C3C3" />
<corners
android:radius="25dp" />
</shape>
Just create an xml file in your drawable folder name as round_corner.xml.And add this following code.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners
android:radius="3dp"
/>
<solid
android:color="#android:color/white"/>
</shape>
At Last you add this xml in background property of your Edittext as follows:-
<EditText
android:id="#+id/ed1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/round_corner"
/>
Done..Definitely it works..
1.) Create rounded_edittext.xml file in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="15dp">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="5dp"
android:bottomLeftRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
<stroke android:width="1dip" android:color="#FF0000" />
</shape>
2.) Put below code in styles.xml file placed in values folder
<style name="largeEdittextText">
<item name="android:textAppearance">#android:style/TextAppearance.Large.Inverse</item>
<item name="android:textSize">15dp</item>
<item name="android:singleLine">true</item>
<item name="android:paddingTop">8dp</item>
<item name="android:paddingBottom">8dp</item>
<item name="android:paddingLeft">5dp</item>
<item name="android:background">#FFB90F</item>
<item name="android:textColor">#android:color/black</item>
</style>
3.) Apply both on edittext in layout file
<EditText
android:id="#+id/userName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center_horizontal"
android:hint="#string/login_userHint"
android:text="admin"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:singleLine="true"
android:textAppearance="#style/largeEdittextText"
android:background="#drawable/rounded_edittext">
</EditText>
if you want to make the border of EditText Round and curve, then just paste this code in Drawable/mystyle.xml (create this xml file) .
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:thickness="0dp"
android:shape="rectangle">
<stroke android:width="1dp"
android:color="#c8c8c8"/>
<corners android:radius="11dp" />
</shape>
Now in your EditText link this file as
android:background="#+drawable/mystyle"

Categories

Resources