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
Related
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.
I currently have this user interface on my app.
I would like to round the edges of the notes like I managed to do in the composing section of the app, as below
I was able to do this by using the following in a file in drawable called timetable_item_border.xml,
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="0dp"
android:color="#000" />
<solid android:color="#color/tile_background" />
<padding
android:bottom="#dimen/tile_padding"
android:left="#dimen/tile_padding"
android:right="#dimen/tile_padding"
android:top="#dimen/tile_padding" />
<!-- <corners android:radius="1dp" /> -->
<corners android:radius="10dp"/>
</shape>
I tried to apply android:background:#drawable/timetable_item_border at the start of the following file but it curved the corners of the notes but removed all the padding, which I didnt want. (I put it at the start of the frame layout but before the linear layout).
This is file:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/note_tile_margin">
<LinearLayout
android:id="#+id/tile_clickable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="#drawable/tile_selector"
android:clickable="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/noteTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="#dimen/tile_padding"
android:layout_toLeftOf="#+id/btn_tile_expand"
android:ellipsize="end"
android:maxLines="#integer/max_tile_lines"
android:singleLine="false"
android:text="Write your message here... "
android:textColor="#color/tile_text" />
<LinearLayout
android:id="#+id/btn_tile_expand"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/click_selector"
android:gravity="top" >
<ImageView
android:id="#+id/btn_tile_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="7dp"
android:src="#drawable/icon_dark_expand" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/tile_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="right"
android:visibility="gone" >
<ImageView
android:id="#+id/btn_tile_links"
style="#style/btn_tile_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:contentDescription="Hyperlinks"
android:src="#drawable/icon_dark_web" />
<ImageView
android:id="#+id/btn_tile_delete"
style="#style/btn_tile_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:contentDescription="#string/deleteNote"
android:src="#drawable/icon_dark_delete" />
<ImageView
android:id="#+id/btn_tile_share"
style="#style/btn_tile_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:contentDescription="#string/share"
android:src="#drawable/icon_dark_share" />
<ImageView
android:id="#+id/btn_tile_copy"
style="#style/btn_tile_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:contentDescription="Copy to clipboard"
android:src="#drawable/icon_dark_copy" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
How should I curve the notes? What am I not seeing correctly?
Note: The original source code comes from here, https://github.com/mick88/notepad, I am just redoing the graphics.
Google have created a view for this very case. The CardView http://developer.android.com/training/material/lists-cards.html
If you use cardview try this
card_view:cardCornerRadius=""
I want to create a textview like the below image. I tried but not able to get like this format.
This is my xml file.
<View android:background="#ff340c1c"
android:layout_width="fill_parent"
android:layout_height="0.5dip"
android:layout_above="#+id/genere"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/genere"
android:text="Search by Movie Genere"
android:layout_above="#+id/rating"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="78dp"
android:textSize="20sp"/>
<View android:background="#ff340c1c"
android:layout_width="fill_parent"
android:layout_height="0.5dip"
android:layout_alignBottom="#+id/genere"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
Use custom background with border and drawableLeft -
drawable/my_rect.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
android:width="0.5dp"
android:color="#color/gray" />
<solid android:color="#color/white" />
<corners android:radius="0px" />
</shape>
In XML:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/genere"
android:text="Search by Movie Genere"
android:layout_above="#+id/rating"
android:drawableLeft="#drawable/someimage" // ADD
android:background="#drawable/my_rect" // ADD
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="78dp"
android:textSize="20sp"/>
Note: Many possible solution exists.
It can be done by using a simple linear layout as a border.
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#EEEEEE"
android:orientation="horizontal"
android:padding="1dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/ic_search_category_default" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Search By Venue" />
</LinearLayout>
</LinearLayout>
For adding an image to the TextView, see android:drawableLeft. For adding a border, you could take a look at 9-patch images. Generate a 9-patch image as described, and set that as the background of the TextView.
I'm currently trying to create a list item similar to the one in the official design guidelines. Still missing is the vertical divider next to the button/image on the right side of each item. Most people seem to use a separate View with a fixed width for that, but the height doesn't scale in my case. It's only shown when I set a fixed height for the divider itself or the parent RelativeLayout. Is it possible to let it scale automatically?
My layout XML for the list item looks like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/sensors_list_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:padding="10dp" />
<TextView
android:id="#+id/sensors_list_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_toRightOf="#id/sensors_list_img"
android:paddingTop="5dp" />
<TextView
android:id="#+id/sensors_list_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:layout_below="#id/sensors_list_name"
android:layout_toRightOf="#id/sensors_list_img"
android:paddingBottom="5dp" />
<ImageView
android:id="#+id/sensors_list_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:padding="10dp"
android:src="#drawable/ic_angle_right" />
<View
android:id="#+id/sensors_list_divider"
android:layout_width="2dp"
android:layout_height="match_parent"
android:layout_toLeftOf="#id/sensors_list_details"
android:background="#ff0000" />
</RelativeLayout>
Try to assign an height related to the image like:
android:alignTop="#id/myimage"
android:alignBottom="#id/myimage"
otherwise you can create a xml drawable and use it with an ImageView :
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:width="1dp" android:color="#000000"/>
</shape>
Update
Remember android:shape="line" doesn't work without stroke
Let's go with a LinearLayout as a parent:
<?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="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/sensors_list_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingTop="5dp" />
<TextView
android:id="#+id/sensors_list_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:paddingBottom="5dp" />
</LinearLayout>
<View
android:id="#+id/sensors_list_divider"
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#ff0000" />
<ImageView
android:id="#+id/sensors_list_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:src="#drawable/ic_angle_right" />
</LinearLayout>
Check this
listView.setDividerHeight(1);
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!