Hey guy's
First of all thanks for reading this.
I'm having trouble to find a way to change my EditText when I loose focus to it.
I would like it to be greyed out when this happens, but I don't want it to be disabled because the user can touch it and edit the text later.
Anyone?
Greetings!
You can set different colors to the text based on an OnFocusChangeListener
Another option is to set a style in xml. See this question for details: Android: change style when focused
To change the opacity, use setAlpha. In this answer I show it how to do it in an animation: Two questions about custom app ui's and AlphaAnimation
Related
I want to have a button like the one in the link below. How can i achieve it just by java code or xml? By the way it's going to be of a different color when pressed. I've explored similar posts but none helped. Any help appreciated.
The button which i want
Just make a View with large rectangle and add what you want(e.g. Label contains 'Number Of Students' and/or something else) in the view.
Then, add onClickListener to the View.
To change clicked colour, refer to here
I have a question about Material Design and semantics.
I try to make the settings of my application and I have only a few fields. So I first try to make the UI like this one, with a LinearLayout and some EditText:
I have to set hour, and I have set OnClickListener to display a TimePickerDialog.
But when I check the settings on Google Agenda, it appear to be a List of Button? (The animation on touch is the same on Button)
Should I use Button and not EditText? Even if it's look like FullWidth Textfield?
Should I use a List rather than LinearLayout?
I am sorry for my bad english...
You can use both approach but if you will use Linear layout that will be good.
For material design you can follow below link:
https://github.com/navasmdc/MaterialDesignLibrary#flat-button
https://github.com/keithellis/MaterialWidget
https://github.com/tekinarslan/AndroidMaterialDesignToolbar
https://github.com/madcyph3r/AdvancedMaterialDrawer
I hope, It will help.
I have a custom view that extends EditText that has ToggleButtons for rich text editing. If I allow autocomplete, which I want to do, the indicator for the current word triggers my detection for style spans.
For example on most devices the autocorrect eligible word is an underline. As you type I have a text watcher that keeps track of the current styles that are applied to the text and adds new spannables if the user toggles a style button. This ends up detecting the underline and turning the toggle on.
I can write code to check if the underline toggle was set before we found the span. (I would actually need to do this for all my styles really since some devices use a background color to indicate the current autocorrect word.) But I'm unsure what I would use to trigger turning the toggle back to off. Check if they typed space? What happens when you select a suggested word?
Has anyone done this? Is there a way to ask if the span is from autocomplete or any other notifications to know the OS drew the span?
This is an old question, but just now I had a similar problem, namely eliminating the unwanted underline before converting the spans into HTML. I found the answer in the source to TextView.
There is a method TextView#clearComposingText() that will remove all styles applied by the IME during autosuggest, preserving all other styles. You could likely call it after every user keystroke, which would remove the underlines.
Hope this helps someone.
I'm looking for a way to have a grayed out text as prefix in an EditText. This text should be not selectable.
It's a bit like the To field when you're composing a message with Gmail. The only (visual) difference is that this text disappears when you start typing.
Is there any trick to achieve this in Android?
Thanks!
You can use an image of the part "EUR 2500". this you can display in your editbox without affecting the rest of the part. Follow the code:
Drawable editTextDrawable = context.getResources().getDrawable(imageId);
editTextDrawable.setBounds(0, 0, editTextDrawable.getIntrinsicWidth(),
editTextDrawable.getIntrinsicHeight());
The drawable can be used inside the edittext as follows:
editTxtItemName.setCompoundDrawables(,
ListViewConstants.editTextDrawable, null, null, null);
As an ultimate solution, you can rewrite the full EditText class by extending it and modifying it in a way that it has a custom Background set by you, and a predefined padding set by you.
Put the EUR as the background, positioning it in the left side, and then give the starting padding of the EditText in such a way that the text the user types, starts right after the EUR text.
This maybe regarded as an overkill or a poor-man's solution to this problem, but still its the ultimate option. Not the smartest one perhaps, and I also don't know if its gonna work for sure :P
All the best!
I'm trying to make iPhone-style EditText element on android.
The one that will have an additional clear button appear on the right after text input.
Adding a new button is not a problem, but I'm a bit stuck with another thing.
A button occupies some space on the right part of EditText, and now characters display beneath the button. How to change maximum shown length of input for EditText?
I want EditText width to be N pixels, and editable area to be N-M pixels.
EditText.setWidth changes width for whole edit box.
EditText.setEllipsize should be the proper solution, but docs are empty, and as I see it truncates text based on some String value.
Applying a LengthFilter cut's the input length to number of characters.
Thanks in advance.
I suspect that android:drawableRight will save you a lot of pain.
Seems I've found a solution.
EditText.setPadding(l,t,r,b) seems to work fine, applying only for editable area
Try this : http://mytechead.wordpress.com/2012/02/07/create-ios-like-cleartextbutton-in-android/
This is a very old question, but thought I'd add my two cents for kicks. I'd probably use a 9 patch for this and set the content area to stop the text before it hits the button area.
This would require creating a custom view so that you can add a button in the desired position using relative layout so that it can be clicked to clear the edittext.
Alternatively you can use the compound drawables, but you would need to implement something like this
Handling click events on a drawable within an EditText so that you can handle the click events. Keep in mind that I doubt the button states (eg the down state) will work using this method.