How to set ImageView in edittext [duplicate] - android

This question already has answers here:
Inserting imageview inside edittext android
(4 answers)
How can I add an image on EditText
(10 answers)
Closed 4 years ago.
I am using the EditText with drawableLeft property and set ImageView in Left side for displaying mobile icon. My Question is how to put Imageview in EditText?
Please help me.
Actually i want like this.
I have tried using linear layout with horizontal. below is xml code.
<LinearLayout
android:weightSum="2"
android:layout_below="#id/welcome"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_weight="1"
android:layout_gravity="center"
android:id="#+id/image_mobile"
android:layout_width="#dimen/_50sdp"
android:layout_height="#dimen/_50sdp"
android:src="#mipmap/ic_launcher" />
<EditText
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_30sdp"
android:layout_toRightOf="#+id/image_mobile"
android:hint="Mobile number"
android:inputType="text" />
</LinearLayout>
But am not able to adjust the image view and edittext.

You should use android:drawableStart
The drawable to be drawn to the start of the text.
DEMO
<EditText
......
android:drawableStart="#drawable/your_icon"
android:drawablePadding="5dp"
/>

Related

How to create material design button with image and text vertically aligned? [duplicate]

This question already has answers here:
Android Material Button with Icon on top of Text
(2 answers)
Closed 2 years ago.
Using Material design, I need to create a button with text and Image aligned vertically.
<com.google.android.material.button.MaterialButton
android:id="#+id/btn"
style="#style/Widget.MaterialComponents.Button.UnelevatedButton"
android:layout_width="160dp"
android:layout_height="160dp"
android:clickable="true"
android:elevation="4dp"
android:fontFamily="#font/roboto_bold"
android:onClick="myfunction()"
android:text="BUTTON"
android:textColor="#android:color/black"
android:textSize="20dp" />
Use android:drawableBottom="..." or android:drawableTop="..." to align text and an image vertically.
dependencies {
implementation "com.google.android.material:material:1.2.0-alpha01"
}
<com.google.android.material.button.MaterialButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawableTop="#drawable/ic_android_black_24dp"
android:drawableTint="#color/white"
app:backgroundTint="#429835"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:text="Hello world" />

Align Textview drawable and text to baseline bottom? [duplicate]

This question already has answers here:
How to add drawable image inside textview
(2 answers)
Closed 4 years ago.
I have a textView with an image and text, I want to align text with the baseline of the image. I am trying but unable to do this. How can I do this? Thanks in advance.
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:drawablePadding="4dp"
android:text="Hello"
android:drawableStart="#drawable/date"
android:gravity="bottom"
android:textColor="#color/black"
android:textSize="10sp" />
I want to text and image like this, they share the same baseline:
Try Below:
Use android:drawableTop to set Image at top.
<TextView
android:id="#+id/news_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="3"
android:drawableTop="#drawable/progress_image"
android:textColor="#color/black"
android:text="Below Text"
android:textSize="10sp" />

how we can design imageView in corner of textView in android? [duplicate]

This question already has answers here:
How to layout text to flow around an image
(9 answers)
Closed 6 years ago.
I am new in android so I am confuse in this design so please help me.
I want to design this type
Have you tried FlowTextView
How to use
Add to your XML layout with your child views inside it:
<uk.co.deanwild.flowtextview.FlowTextView
android:id="#+id/ftv"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:padding="10dip"
android:src="#drawable/android"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="400dip"
android:padding="10dip"
android:src="#drawable/android2"/>
</uk.co.deanwild.flowtextview.FlowTextView>
Then in your code:
FlowTextView flowTextView = (FlowTextView) findViewById(R.id.ftv);
Spanned html = Html.fromHtml("<html>Your html goes here....");
flowTextView.setText(html);
Add the dependency:
compile 'uk.co.deanwild:flowtextview:2.0.2'
Output:
Enjoy...

Android EditText with icon and vertical line [duplicate]

This question already has answers here:
Android EditText draw a divider line between its drawable and its text
(4 answers)
Closed 6 years ago.
I need an EditText exactly like this:
EditText with icon and vertical line
Is it possible doing this at Android XML file?
Maybe this code helps you
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edit_text_selector">
<EditText
android:id="#+id/input"
android:layout_marginLeft="-10dp"
android:layout_toRightOf="#+id/your_icon"
android:text=""
android:padding="10dp"
android:background=""
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<!-- icon -->
<ImageView
android:padding="3dp"
android:id="#+id/icon"
android:src="#drawable/perm_group_personal_info"
android:layout_width="40dp"
android:layout_height="40dp" />
</RelativeLayout>
Yes.
Use FrameLayout / RelativeLayout.
either way you can position imageButton with the image as src and costume drawable that will have only 1 side line.

Image + Text to be centre alligned in button

I have a Button with its width as match_parent. And I want a image/icon with a text in its center. I have triedandroid:drawableStart attribute but its of no help. I don't know what I am missing. Is there any one who is also facing the same problem.
Note:This link is not solving my problem. I am attaching my button portion of xml
<Button
android:background="#drawable/blue_button"
android:id="#+id/btn_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:drawableStart="#drawable/ic_list"
android:text="#string/btn_schedule"
android:textColor="#android:color/white" />
After adding these attribute my text is coming on center but image/icon is still on left side of button. Can any body help!!!
You might want to check my answer to this question:
Android Button with text and image
Its an ugly solution but it you want the image and text to be centered as a group in the button rather than text center and drawable padded from the side then its the only way I have found.
100% working
<FrameLayout
style="?android:attr/buttonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#null"
android:clickable="false"
android:drawableLeft="#android:drawable/ic_delete"
android:focusable="false"
android:gravity="center"
android:minHeight="0dp"
android:minWidth="0dp"
android:text="Button Challenge" />
from here
This works for me. Basically play with the paddingLeft and PaddingRight of the button to get the text and image close together to the center.
Note: Might be an issue with rather long texts.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="search button"
android:drawableStart="#drawable/ic_action_search"
android:paddingLeft="60dp"
android:paddingRight="60dp"/>
</LinearLayout>
I had the same problem and I hadn't found anywhere clear solution. BUT I got some information which also help me to provide following solutions (I have chosen the second one):
Create image which will contain your image and text
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableTop="#drawable/YOUR_IMAGE"
android:gravity="center_horizontal|center_vertical" />
It is not so clear and you have to add more complicated changes to your layout but it is easier to modify the text later
<FrameLayout
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:layout_height="50dp"
android:layout_width="match_parent" />
<TextView
android:text="sample"
android:layout_height="50dp"
android:layout_width="wrap_content"
android:drawableLeft="#drawable/YOUR_IMAGE"
android:gravity="center_horizontal|center_vertical" />
</FrameLayout>
I tried android:drawableTop
The image shown in the center of the button

Categories

Resources