How do I create an input box using Android's Layout mechanism? - android

Using Android's Layout mechanism, how do I create an input box with the password icon, and a split between the icon and the input field, as shown below? I'd like to have the border around the input field as well.

you can use imageview and an edit text inside a layout like this
<RelativeLayout
android:layout_width="#dimen/_280sdp"
android:layout_height="#dimen/_30sdp"
android:id="#+id/rl_password"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="#dimen/_15sdp"
android:layout_height="#dimen/_15sdp"
android:src="#drawable/key"
android:layout_centerVertical="true"
android:id="#+id/iv_password"/>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Password"
android:layout_toRightOf="#+id/iv_password"
android:layout_centerVertical="true"
android:background="#00000000"
android:layout_marginLeft="#dimen/_8sdp"/>
</RelativeLayout>

Try This ....
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/background"
android:layout_margin="40dp">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="10dp"
android:src="#drawable/your_image" />
<View
android:id="#+id/view"
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#dbdbdb" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:padding="10dp"
android:inputType="textPassword"
android:background="#android:color/transparent"/>
</LinearLayout>
#drawable/background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#fafafa" />
<corners android:radius="2dp" />
<stroke android:width="1dp" android:color="#dbdbdb" />
</shape>
</item>
</selector>

Sorry, but you will not find a tutorial here.
we guys here don't put tutorial if you have any problem in implementing your code you can ask.
for now, you can watch this tutrial may help.

Related

Adding background to edittext breaks the layout

I'm try to design an input text view. Here is the code I use.
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="7dp"
android:layout_margin="10dp"
app:cardCornerRadius="22dp"
android:backgroundTint="#ff7171">
<AutoCompleteTextView
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="#string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true"/>
</android.support.v7.widget.CardView>
The thing I try to achieve is round corners and a little shadow under the layout. Here is the output of this code:
This gives me 2 disadvantage. First, I can't use floating label with this. This is a low priority. What bugs me is: the underline. I am trying to remove it. The common way people suggest was use:
android:background="#null"
However, when I use it, the output becomes like this:
How can I overcome this issue?
Create a file named background under drawable folder and paste the following codes.
<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/background.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#00000000"/>
<stroke
android:width="1dp"
android:color="#00000000"/>
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
</shape>
Then rewrite the autocompletetextview as
<AutoCompleteTextView
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background.xml"
android:hint="#string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
This might help you:
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentPadding="16dp"
android:backgroundTint="#ff7171"
app:cardCornerRadius="16dp">
<AutoCompleteTextView
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#null"
android:hint="#string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
</android.support.v7.widget.CardView>
Here is the result:

Custom EditText into Android

I'd like to put attach file icon into EditText for example how it was made into WhatsApp. How can I do it?
That is not a custom EditBox. Here EditText is wrapped with parent view with other ImageViews.
In whatsapp example there is a Imogi ImageView, An EditText, An Attach ImageView, and a camera ImageView inside a LinearLayout. And parent LinearLayout is having round corner background.
You can also use Drawable left and Drawable right, but I will not suggest that because that does not have much control.
Just a suggestion:
I always want to save time. Here is an whatsapp clone, you can just pull it and use its views.
https://github.com/Shahar2k5/whatsappClone
This guy has done good work in this library.
Use drawableRight attribute in EditText
<EditText
android:id="#+id/account_et"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:drawableRight="#drawable/icon_backall" //your drawable which you want to use
android:ems="10"
android:hint="#string/str_md_email"
android:padding="10dp" >
</EditText>
You have to manage like below image :
For above UI design code is below :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="#dimen/_10sdp"
android:background="#drawable/stockbg"
android:orientation="horizontal">
<EditText
android:id="#+id/edt_sendMeassage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/_10sdp"
android:layout_marginRight="#dimen/_10sdp"
android:layout_weight="1"
android:maxLines="4"
android:backgroundTint="#android:color/transparent"
android:paddingLeft="#dimen/_10sdp"
android:paddingRight="#dimen/_10sdp"
android:textSize="#dimen/normal_input_text_size" />
<LinearLayout
android:id="#+id/ll_send"
android:layout_weight="6"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="#dimen/_40sdp"
android:layout_height="#dimen/_20sdp"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:src="#drawable/ic_next_arrow"
android:tint="#color/color_gray" />
</LinearLayout>
</LinearLayout>
I'd like to put attach file icon into EditText for example how it was made into WhatsApp.
if you want to add icon in EditText you can use
android:drawableStart=""
android:drawableEnd=""
android:drawableTop=""
android:drawableLeft=""
android:drawableRight=""
how it was made into WhatsApp. How can I do it?
That is not Custom Edittext
You need to wrap your ImageView and EditText in side a ViewGroup like LinearLayout or RelativeLayout
SAMPLE CODE
<LinearLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:padding="10dp"
android:background="#drawable/test"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_camera" />
<EditText
android:layout_width="0dp"
android:background="#android:color/transparent"
android:layout_weight="1"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:src="#drawable/ic_menu_camera" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:src="#drawable/ic_menu_camera" />
</LinearLayout>
android:background="#drawable/test"
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#color/colorPrimary" />
<corners android:radius="25dp" />
</shape>
OUTPUT
You need to put edittext and attach icon in layout (according to your need) and set rounded background to parent layout
like this
<RelativeLayout
android:id="#+id/sendLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/roundedbg"
android:orientation="horizontal">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/attachFile"
android:background="#null"
android:padding="#dimen/five_dp" />
<ImageView
android:id="#+id/attachFile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"
/>
</RelativeLayout>
roundedbg.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<stroke android:width="3dp" android:color="#B1BCBE" />
<corners android:radius="10dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
better you use wrap edittext and imageview in relative layout like below
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp">
<EditText
android:id="#+id/etPassword"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/custom_edittext"
android:hint="Password"
android:minLines="10"
app:passwordToggleEnabled="true"
android:singleLine="true"
android:inputType="textPassword"
android:textSize="14sp"
android:paddingLeft="20dp"
android:layout_weight="1"
android:paddingRight="20dp"
tools:ignore="MissingPrefix" />
<ImageView
android:id="#+id/ivPasswordToggle"
android:layout_width="24dp"
android:elevation="10dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:layout_height="24dp"
android:background="#drawable/ic_remove_red_eye_black_24dp"/>
</RelativeLayout>
output :
in java code use click on imageview

Android layout design

I'm sorry if I asking a stupid question here.
I'm looking for android layout design. Is there has a web easy for us to design the android layout and finally generate xml code to android studio.
I wanted to have a layout design as image below, however I don't think it is possible to do using android studio layout.
Try this xml code..
Screenshot
<?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:padding="#dimen/value_10"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/title1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/round_corner_up"
android:padding="#dimen/value_10"
android:text="Choose Station"
android:textColor="#color/black"
android:textSize="#dimen/txt_large" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title1"
android:layout_marginTop="-15dp"
android:background="#drawable/round_corner_up">
<EditText
android:layout_width="350dp"
android:layout_height="70dp"
android:layout_margin="#dimen/value_10"
android:background="#drawable/round_corner_square" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="#dimen/value_10">
<TextView
android:id="#+id/title2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/round_corner_up"
android:padding="#dimen/value_10"
android:text="Within Next"
android:textColor="#color/black"
android:textSize="#dimen/txt_large" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title2"
android:layout_marginTop="-15dp"
android:background="#drawable/round_corner_up">
<Spinner
android:layout_width="350dp"
android:layout_height="70dp"></Spinner>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/value_20"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:text="Arrivals"
android:textSize="20sp"
android:drawableLeft="#drawable/drawable1"
android:layout_height="#dimen/value_70" />
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:text="Departures"
android:textSize="20sp"
android:drawableLeft="#drawable/drawable2"
android:layout_height="#dimen/value_70" />
</LinearLayout>
round_corner_up.xml
<?xml version="1.0" encoding="utf-8"?><!-- res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">
<solid android:color="#7B7D7B" />
<stroke
android:width="3dip"
android:color="#7B7D7B" />
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
round_corner_square.xml
<?xml version="1.0" encoding="utf-8"?><!-- res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle">
<solid android:color="#color/white" />
<stroke
android:width="3dip"
android:color="#color/light_gray" />
<corners
android:bottomLeftRadius="15dp"
android:bottomRightRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp" />
You need to divide the layout in smaller elements. e.g. Choose station will be a TextView having a background image and text on it "Choose Station". Below that there will be a Relativelayout with image background and a EditText. There will be a search button with magnifying glass as background drawable. This will be aligned to right of parent so that it be on top of Edittext.

Android: Create circle looks button with background image

Hello guys i know this is not a new question. I am getting help from HERE. In which i have success to make circle button with plane background but i want to make a button with background image like this:
Here is related code for the layout:
<LinearLayout
android:id="#+id/viewLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:background="#color/lighter_gray"/>
<Button
android:id="#+id/btnEdit"
android:background="#drawable/button_circular"
android:ellipsize="none"
android:layout_width="0dp"
android:layout_weight=".18"
android:layout_height="wrap_content" />
<View
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_weight="0.2"
android:layout_gravity="center_vertical"
android:background="#color/lighter_gray"/>
</LinearLayout>
#drawable/button_circular
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#color/app_main_color"/>
<stroke android:width="2dp" android:color="#color/app_main_color" />
</shape>
I also want to know is this a right way to get button like this? Thanks in advance.
You should use Imageview Instead of Button
<ImageView
android:id="#+id/btnEdit"
android:background="#drawable/button_circular"
android:ellipsize="none"
android:layout_width="0dp"
android:layout_weight=".18"
android:layout_height="wrap_content" />

Card Interface: Can't fit contents and text is clipped

I'm making an app with it's contents inside card-like views but I am having a couple of problems:
I can't get the label line (the blue line) to move away from the card text. I've tried both padding and margin (on both line imageview and textview from text) and nothing seems to work here.
The bottom part of the card title is getting cropped because of the line spacing. How can I fix this and keep the line spacing?
Check this screenshot for better understanding: http://imgur.com/qsoCFrB
Here's the code to the card background and the interface itself:
card_bg:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle"
android:dither="true">
<corners android:radius="1dp"/>
<solid android:color="#bdbdbd" />
</shape>
</item>
<item android:bottom="2dp">
<shape android:shape="rectangle"
android:dither="true">
<corners android:radius="2dp" />
<solid android:color="#android:color/white" />
<padding android:bottom="6dp"
android:left="6dp"
android:right="6dp"
android:top="4dp" />
</shape>
</item>
</layer-list>
main acitivity:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="4dp"
android:background="#drawable/card_bg" >
<ImageView
android:id="#+id/iconView0001"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="6dp"
android:src="#drawable/icon_example" />
<ImageView
android:id="#+id/labelSource0001"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/cardText0001"
android:layout_marginTop="4dp"
android:background="#drawable/card_label" />
<TextView
android:id="#+id/cardTitle0001"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/cardText0001"
android:layout_toRightOf="#+id/iconView0001"
android:fontFamily="sans-serif-condensed"
android:maxLines="2"
android:paddingLeft="4dp"
android:lineSpacingExtra="-6dp"
android:text="#string/card_title_002"
android:textColor="#717171"
android:textSize="16sp" />
<TextView
android:id="#+id/cardText0001"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/iconView0001"
android:fontFamily="sans-serif"
android:layout_marginTop="4dp"
android:maxLines="1"
android:text="#string/card_desc_002"
android:textColor="#acacac"
android:textSize="12sp" />
</RelativeLayout>
</FrameLayout>
Thanks in advance.
this is the creator of the Gist on GitHub!
Have you tried increasing padding on the RelativeLayout, perhaps that could fix the problem? Or even on the TextView element?
Try doing that and see what the results are.
EDIT: Also, why is there negative line spacing within the Text View?
DOUBLE EDIT: So what was happening is that your layout_alignBottom in the linkTitle TextView was shorter than the height of two lines of text, therefore it was cropping the title to limit the height of the TextView to that of the FavIcon ImageView. Removing this property fixes the issue.
Similar issue goes for the label shape, that alignBottom is what's messing it up.
Change layout_alignBottom to layout_below and then padding/margin should affect the position as you please.
Here is the updated version of your code that should remedy your issues:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linkCardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ccc" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="4dp"
android:background="#drawable/card_bg">
<TextView
android:id="#+id/linkTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/faviconView0001"
android:padding="4dp"
android:maxLines="2"
android:text="#string/link_title_001"
android:textColor="#717171"
android:textSize="17sp" />
<TextView
android:id="#+id/linkDesc0001"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linkTitle"
android:paddingTop="6dp"
android:paddingBottom="9dp"
android:fontFamily="sans-serif"
android:maxLines="1"
android:text="#string/link_desc_001"
android:textColor="#acacac"
android:textSize="13sp" />
<ImageView
android:id="#+id/faviconView0001"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="6dp"
android:layout_alignParentLeft="true"
android:src="#drawable/favicon_example" />
<View
android:layout_height="0dp"
android:layout_width="fill_parent"
/>
<ImageView
android:id="#+id/labelSource0001"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linkDesc0001"
android:background="#drawable/card_label" />
</RelativeLayout>
</FrameLayout>
I hope that all of this helps!

Categories

Resources