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>
Related
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
I want to change Button background color programmatically the button
shape(oval). I have changed in xml.
This is the code:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="20dp"/>
<solid android:color="#f9f9f9"/>
<stroke
android:width="2dp" android:color="#FFFF4917" />
</shape>
I am using Button.backgroundColor(COLOR.RED) to change this Button but problem is that it's changing button color, but it is making my button rectangular shape(default shape of a button)
You could modify it using this simple method down below
GradientDrawable BackgroundShape = (GradientDrawable)btn.getBackground();
BackgroundShape.setColor(Color.BLACK);
Use it. It will make your rectangular shap to oval shap when click on button.
style_login_button.xml
<?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="oval">
<solid android:color="#color/colorDeepOrange"/>
<size android:width="120dp" android:height="120dp"/>
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="oval">
<solid android:color="#color/colorOrange"/>
<size android:width="120dp" android:height="120dp"/>
</shape>
</item>
<item >
<shape android:shape="oval">
<solid android:color="#color/colorOrange"/>
<size android:width="120dp" android:height="120dp"/>
</shape>
</item>
</selector>
And apply to Button . Like -
<Button
android:id="#+id/btnSignin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text_btn_login"
android:textColor="#color/colorWhite"
android:textSize="25dp"
android:padding="30dp"
android:textAllCaps="false"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:background="#drawable/style_login_button"/>
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 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.
I am using custom drawable to set background of edit text.Following is the code for edit text background
<?xml version="1.0" encoding="utf-8"?>
<corners android:radius="1dp" />
<stroke
android:width="1dp"
android:color="#595C65" />
<solid android:color="#ffffff" />
It displays the edit box with rectangle background .But i want to set edit text background with L shape(set left and bottom backgrounds).
Without using external images and i want to set these background via drawable xmls.
Expected output:
Current output:
I found a solution for these:
text.xml:
<?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="#000000" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
<item android:bottom="3px" android:left="3px">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
main.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="match_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/editText1"
android:background="#drawable/text"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="30dp"
android:ems="10"
android:gravity="center_horizontal"
android:padding="2dp"
android:password="true" />
</RelativeLayout>
Expected Output:
Without using external images we can get a output with the help of drawable text.xml
Using a drawable this should work :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#ffffff" />
<stroke
android:width="1dp"
android:color="#555555" />
</shape>