When I setCompoundDrawables or setCompoundDrawablesWithIntrinsicBounds with a drawable in a EditText. Everytimes show layout of activity, I'm trying to add a x icon at the end of the text field but it's not working in first create. But refresh, icon x showing.
Do setCompoundDrawables set icon failed?
Please Help me.
It is sample problem same but i can't fix my problem: setCompoundDrawablesWithIntrinsicBounds is not working properly
drawXRemove = getResources().getDrawable(R.drawable.ic_iconX);
drawXRemove.setBounds(0, 0, drawXRemove.getIntrinsicWidth(), drawMarkXRemove.getIntrinsicHeight());
editText.setCompoundDrawables(null, null, drawXRemove, null);
You are setting Compound Drawable in wrong way. use:
editText.setCompoundDrawablesWithIntrinsicBounds(0, 0,drawXRemove, 0);
OR
editText.setCompoundDrawablesWithIntrinsicBounds(0, 0,R.drawable.ic_iconX, 0);
Try using icon directly from drawable as below
editText.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.drawableRight, 0);
Thanks for help, I do it. It's problem when different func call set null for EditText.
Related
I have an edittext and according to the code I get from web service I need to set drawable right to my edittext.
I get the response code by calling a service as soon as the edittext focus changes, so if the edittext gain focus again the image should be gone as well.
But if the response code is different from these cases I need to set that drawable as transparent, null or I have to make it's visibility gone.
ediTextAbc.setCompoundDrawablesWithIntrinsicBounds(R.drawable.abc,0,0,0);
Set 0 or null where you don't want drawable
Try :
ediTextIbanEft.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
OR
ediTextIbanEft.setCompoundDrawables(null, null, null, null);
In setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon, 0, 0, 0);
set 0 where you don't want drawable.
In my application I change color of Top drawable of Textview using below code.
tvTopDrawable.setColorFilter("#E1BEE7", Mode.SRC_ATOP);
Now I want to clear this color from my drawable.
I have tried tvTopDrawable.clearColorFilter();
But it seems its not working sometime.
I used that same image in other Activity of my Application.
Where to write clearColorFilter() so it clears the color from drawable,Can anyone help with this?
Thanks in Advance.
Try setting color filter to transparent
tvTopDrawable.setColorFilter("#00E1BEE7", Mode.SRC_ATOP);
I am using BulletSpan(BulletSpan.STANDARD_GAP_WIDTH)
How can I change its icon from a circle to ✓?
SpannableString s = new SpannableString(text+"\n");
s.setSpan(new BulletSpan(BulletSpan.STANDARD_GAP_WIDTH), 0, text.length(), 0);
I was also trying to style the bullet icon used by Android but didn't find any answers online. I ended up using an alternative approach which may help you further as well.
I didn't use BulletSpan but I used LeadingMarginSpan instead. You can add whatever character you want as icon (such as your tick character) in the text to be "spanned". By setting the first line margin and rest margins correctly you can achieve the same effect as the BulletSpan.
For EditText that going be filled with RTL text, is there a way to change the gravity of the error drawable (and popup of course) ?
here is an example of regular error drawable
so since the text entered is RTL i would like the pop up to show up at the LEFT side of the EditText
i tried to apply custom drawable , but Drawable doesnt seem to have any setGravity method.
thanks in advance.
It's not possible by normal means, however you can extend the Android TextView class and change the layout that Android uses to inflate the popup. I haven't tried this myself but it could work.
I did a quick look in the source of TextView and found this line
final TextView err = (TextView) inflater.inflate(com.android.internal.R.layout.textview_hint,
null);
Which references to this layout.
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/popup_inline_error"
android:textAppearance="?android:attr/textAppearanceSmallInverse"
/>
Adding gravity here could do the trick. A similar approach for the drawable could apply.
It's over a year, but if it helps anyone else, you can use:
myEdit.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_error, 0, 0, 0);
but it will stay until you remove it
myEdit.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
I want to set a setError method to my EditText, with a custom icon instead of the default Android icon. So I tried this:
((EditText)findViewById(R.id.edtTitle)).setError(getResources().getText(R.string.errEmptyTitle),
getResources().getDrawable(R.drawable.ico_warning_small);
It shows me the custom message, but not the custom icon. I tried this as well:
Drawable warning = (Drawable)getResources().getDrawable(R.drawable.ico_warning_small);
((EditText)findViewById(R.id.edtTitle))
.setError(getResources().getText(R.string.errEmptyTitle), warning);
Pretty much the same, but I still decided to give it a go. However this also didn't help - I still can't see the icon.
I tried to use some other Android system icon, just to see if I see them and no, I don't see them as well.
So what am I doing wrong? Is there any way to set that custom icon?
You need to set the bounds on the drawable before using it in setError.
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
editText.setError("error", drawable);
If you don't want to show any icon at all, use
editText.setError("error", null);
This issue is discussed and resolved here:
EditText setError() with icon but without Popup message
I hope that by extending the answer it would not get auto-converted to a comment.
Drawable customErrorDrawable = getResources().getDrawable(R.drawable.error_icon);
customErrorDrawable.setBounds(0, 0, customErrorDrawable.getIntrinsicWidth(), customErrorDrawable.getIntrinsicHeight());
editText.setError("please enter data",customErrorDrawable);