EditText with vertical line - android

I'd like to create the following custom EditText. How to make the vertical bar like the one on the picture?

Style edittext_custom_style.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="#75d0e2" />
</shape>
</item>
<item android:left="5dp">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
xml:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edittext_custom_style"/>

Create same bar drawable and assign drawableLeft to edittext
Code put image in respective drawables like drawable-xhdpi etc
Sample is here.
<EditText
android:id="#+id/password"
style="#style/inputFieldStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/password_icon"
android:hint="#string/password_hint"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:maxLines="1"/>

Related

How can i move the arrow to the right side in Spinner

I am trying to move the arrow button the the right side so it wont be in my text
any one can help me??
Button
this is the style code:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<padding android:right="10dp"/>
</shape>
</item>
<item>
<bitmap android:src="#drawable/style" android:gravity="center|right"/>
</item>
</layer-list>
</item>
</selector>
I tried to change gravity but it wont work
Hey you can use material design button that will helpful
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:iconGravity="end"
android:background="#android:color/white"
android:backgroundTint="#android:color/white"
android:text="A+20"
app:icon="#drawable/ic_baseline_arrow_forward_24"
style="#style/Widget.MaterialComponents.Button.TextButton.Icon"
/>
source: https://material.io/components/buttons/android#text-button

How can I write a letter in my xml file?

Hello I have this triangle that I did with xml on Android Studio :
<item>
<rotate
android:fromDegrees="135"
android:pivotX="7%"
android:pivotY="65%" >
<shape
android:shape="rectangle" >
<solid
android:color="#color/blue" />
</shape>
</rotate>
</item>
And what I want is to put a letter at the right of the triangle. How can I do this ?
Thank you very much !
I don't think you can put text in the drawable itself.
What you could do is have your text as a text view and set its background as the drawable.
Or create a button and set its background to your drawable and set the text with the setText() method.
Something like this:
Make a triangle.xml and put it into your drawable folder:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<rotate
android:fromDegrees="135"
android:pivotX="7%"
android:pivotY="65%">
<shape android:shape="rectangle">
<solid android:color="#color/colorPrimary" />
</shape>
</rotate>
</item>
And then make an imageView, put the triangle as a background and a textView on its side all wrapped inside a linearLayout with orientation horizontal.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/triangle"/>
<TextView
android:text="A"
android:textSize="100dp"
android:includeFontPadding="false"
android:padding="0dp"
android:layout_width="100dp"
android:layout_height="100dp" />

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>

How to design EditText and Button in 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.

How to make a "L" shaped edit text drawable selector in android

I am trying to create a EditText as below
Question:
How can i write a selector for this and set as background
I do not want to place a image
You need to use a <layer-list> to accomplish what you want. Taken from this answer
res/drawable/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>
res/layout/activity_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:
This would work
Layout
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:layout_margin="5dp"
android:paddingLeft="5dp"
android:hint="Email"
android:background="#drawable/test_edit"
android:id="#+id/editText" />
Layer_list
<item android:drawable="#color/lightBlue"/>
<item android:drawable="#color/darkBlue" android:left="2dp" android:bottom="2dp" />
Color
darkBlue #ff1ca9ff
lightBlue #ffb6f1ff
Not sure if this may help you but I would just create through the xml and use the Android 4.4 theme to style it L shaped. I would then set the background color to blue. This is how it done:
Create the color.xml file, to enter the color values you need.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="dodgerblue">#1E90FF</color>
<color name="lightskyblue_1">#B0E2FF</color>
</resources>
Then, in your EditText, set the color as follows
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="asdsadasdasd"
android:textColor="#color/lightskyblue_1"
android:background="#color/dodgerblue"
/>
If you need more colors, here is a useful link.
Hope this helps :)

Categories

Resources