How can use Image In editText Android - android

How can i use above image inside of edit text Android?

You can use the "drawableLeft" attribute of EditText. For example:
android:drawableLeft="#drawable/ic_user"
http://developer.android.com/reference/android/widget/TextView.html#attr_android:drawableLeft

user this in your edittext
<EditText
...
android:drawableLeft="#drawable/my_icon" />
Another way is that you can create ImageView for that icon. This way you have more control on placing it

Add left paddding and set EditText background to your drawable:
android:paddingLeft="10dp"
android:background="#drawable/my_icon"

Related

How to delete translucent grey background in Fragment?

I'm trying to use Fragmentto put ImageButton in my app, but i don't want to see translucent grey background like this:
i want to see only round button. How to do it?
You can also use this
android:background="#android:color/transparent"
Put below property in ImageButton.
android:background="#null"

How to add fixed text to left of AutoCompleteTextView?

I want to implement AutoCompleteTextView something like what Gmail app in Android does.
I am not sure how to set "To" fixed text on the left side of AutoCompleteTextView.
How is this implemented? Do I have to put TextView inside AutoCompleteTextView to show "To" label. If I do that my cursor starts from the beginning of AutoCompleteTextView and not after TextView.
How should I achieve this view
You can put a TextView to the left of the AutoCompleteTextView. Use a horizontal LinearLayout for that. You can set the border (the underline with the little ticks) on the linear layout if you want one.
My style of implementation of it is to use android:drawableLeft. Create a drawable(could be image) first which in your case "To". Then apply it in the xml declaration of your AutoCompleteTextView like this.
<AutoCompleteTextView
android:id="#+id/auto_complete_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/to_drawable_label"/>
I hope this helps. :)
you just need to create an adapter and set it to AutocomleteTextView.

Android: using image instead of text on a button

I've been working on my android calculator and i can't seem to insert an image instead of text on a button. For example sqrt I don't want to have sqrt written on my button i want the image of the symbol on it, the same goes for x^y and alot of others. I have my custom background of the button working just fine. Thank you for your help in advance :)
EDIT:
Thats not what i wanted i did manage to get my custom button and thats fine. On my button since its a calculator button i have android:text on it saying sqrt. I want to remove that and insert another png on my button showing the symbol of the square root instead of that text. Thank you for quick responses.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/imageName"/>
You can have both text and image (or no text) when using the attribute drawableTop, drawableBottom, drawableLeft and drawableRight.
And for positioning the image how you want, consider using: paddingTop, paddingBottom, paddingLeft and paddingRight.
You can do this by ImageButton:
<ImageButton
android:id="#+id/submitEmailButton"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_gravity="right" android:layout_marginRight="15dip"
android:background="#drawable/ic_submit" />
Here ic_submit is the image you want to show as a button.
I used this tutorial and it worked perfectly for me: http://www.mkyong.com/android/android-imagebutton-selector-example/
I haven't seen your code but basically you should remove the "text" tag from your xml and it should appear the image without text then.
I don't know if that's exactly what you were looking for or not, but I reccomend you to follow the tutorial and for sure it will work for you ;)
There are a number of alternatives you can try to implement to build your SQRT button:
draw the button as a 9-patch drawable so your SQRT symbol won't get distorted;
use a RelativeLayout with a button inside and implement a selector
You can simply set background for the Button and keep its text blank.

Add a title or description to an EditText

If you open an app like gmail, and you compose a new email in the To and Subject lines, it says To and Subject in the respective EditText's. How do you add a title like that to an EditText? Are those custom views? Or is it possible to do that with the default widget?
Thanks.
It is called a hint.
Set your hint programatically or use it as xml attribute.
I think the attribute hint is what you are looking for.
Here is some sample code:
<EditText android:hint="Write Caption" />

EditText not wrapping its content

I am trying to create an EditText which toggles its state between read only and write mode.
My XML is as below:
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/textArea"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="4"
android:inputType="textMultiLine">
</EditText>
In my code i do the following :
textArea = (EditText) convertView.findViewById(com.pravaa.mobile.R.id.textArea);
//isEditable decides if the EditText is editable or not
if(!isEditable){
textArea.setInputType(InputType.TYPE_NULL);
}
//the view is added to a linear layout.
addView(textArea);
My issue is that the text does not get wrapped. Am i missing out on something? Kindly help me with this. I have also attached an image of my output.
The text set in the view is "12345678901234567 90123456789012345678901234567890 Nationwide Campaign New"
I was able to solve this issue by removing
android:inputType="textMultiLine"
To achieve the non-editable feature I used
setFocusable(false);
I guess that by calling this ...
textArea.setInputType(InputType.TYPE_NULL);
you override the flag InputType.TYPE_TEXT_FLAG_MULTI_LINE. Try calling this instead...
textArea.setInputType(InputType.TYPE_NULL|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
This line will make the text multi-line and will wrap the text
textArea.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
You'd probably also want to call setLines(n) to set the height of the textArea.
Try to replace:
editText.setInputType(InputType.TYPE_NULL);
with:
editText.setRawInputType(InputType.TYPE_NULL);
I would say that by using textArea.setInputType(InputType.TYPE_NULL); you remove the textMultiLine from your xml.
Just set textMultiLine isn't enough. Try this:
textArea.setHorizontallyScrolling(false);
textArea.setEllipsize(null);
textArea.setInputType(InputType.TYPE_NULL|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
What me helped was:
edtText.setInputType(InputType.TYPE_NULL);
edtText.setSingleLine(false);
It seems that the setSingleline Attribute in the XML file is ignored.

Categories

Resources