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.
Related
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.
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 can't change its color or use alpha because the background may change and I won't know its color!
Is there any other way to set it to invisible ?
Also I don't want to set the text view invisible since I want the background to be visible!
Try:
textView.setTextColor(getResources().getColor(android.R.color.transparent));
You can set a textview to INVISIBLE:
myTextView.setVisibility(View.INVISIBLE);
That way the textview will still be present but not seen
Something like this..
String text = "Invisible Text";
TextView text1 = new TextView();
text1.setTag(text);
why not, set text value as empty string when you want to make it invisible. keep backup of the original value so that you can use it later when required.
I'm trying to change the text color in my widget depending on an if. So I have my remoteViews sorted and I can change the actual text with no problem but when I try and change the color using R.color.red it just shows up as black.
RemoteViews remoteViewSmall = new RemoteViews(this.getPackageName(), R.layout.smallwidgetlayout);
remoteViewSmall.setTextColor(R.id.widgetdatasmall, R.color.red);
Is this an incorrect way of retrieving the color "red" I have set in my colors.xml?
You can use the Color.RED. Would that be what you are looking for?
Or are you trying to re-define the colors?
Try this if that is the case:
remoteViewSmall.setTextColor(R.id.widgetdatasmall, getResources().getColor(R.color.red));
It might be because of layout re use.
Set the value on every possible condition. That means set the value to red if you have to and otherwise set it to black.
I want to set start margin only for the first line of TextView (Not first line of each paragraph)? I have used the following code:
SpannableString s = new SpannableString("this is a test"+"\n"+"this is a test");
s.setSpan(new android.text.style.LeadingMarginSpan.Standard(30, 0), 0, s.length(), 0);
textView .setText(s);
Here start margin is getting set for all lines of the Paragraph.. I don't want that. I want start margin to be applied for first line only.. Pls help..
You actually already answered your own question.
All you need to do is to set span lenght to 1 instead of s.length().
if (s.lenght() > 0) {
s.setSpan(new android.text.style.LeadingMarginSpan.Standard(30, 0), 0, 1, 0);
}
That way margin will only be applied to the first paragraph.
As it has been suggested here, I also think the best solution is to simply add a few spaces at the beginning. If you only need the margin space at the very first line of the TextView, I don't see any reason why you'd need to do something really advanced.
If you need to change or use the text in the TextView at a later point, you can just use the substring() method to get only a part of the string, i.e. s.substring(2, s.length());
It's not a perfect solution, but I think it'll do.