Disable misspelling flag of specific words in app? - android

Our company's name always comes up as misspelled (the red underline) when typed into EditText fields in our app. Is there a way I can disable the misspelling flag for a specific word to avoid this nagging feature?
And before someone suggests android:inputType="textNoSuggestions", I would still like spellcheck to be available to that specific field, and only exclude our company name.

I have no idea if it'll work, but you can try putting android.text.style.LocaleSpan over each occurrence of the company name, using Locale.ROOT (which has no language) as the target locale.
(Most of the time you encounter a CharSequence in a text view it can be cast to Spannable. If it can't, just copy its contents into a SpannableStringBuilder.)

Related

How to test the android app language changed or not?

In my android app, I have 3 options for language selection.i.e; Hindi,English,French
Programmatically changed default language(English) to Hindi.
How to verify whether app language changed to Hindi or not.(programmatically)
please help
To check whether language changed or not there may be many ways to verify but simply you can assert page title or that drop down text with expected text.
When the language is changed, take the reference of any text or tile or any element placeholder or label, and verify the string by using equalsIgnoreCase("") method.

gender-dependent locale String resources Android

I'm implementing an app in Hebrew, and I like it to be user-friendly in such way that at the first time the user logs on, there will be a question "Are you a male or a female?". After answering this question, I want most of the strings to be gender-dependent
(E.g. in Hebrew the question "Would you like some coffee?" will be
תרצה לשתות קפה?
for a male, and -
תרצי לשתות קפה?
for a female)
Meanwhile my app supports English and Unisex-Hebrew Locales, so I'm using String resources (like R.string.somevalue) and I know how to handle values-he and values-en.
Let's say I can ask for is_male() and is_locale_hebrew() at anytime, I saw this answer but it won't help my case since there are a hell lot of strings in my working-already app and I want the solution to add only xml files (hopefully) with the less needed change in my "Activity"s code.
I thought maybe overloading the parser that looks for the xml files will do the magic, but I have no clue where to start from.
My question divides into two parts:
A. How can I implement gender-dependnt String-resources?
B. (Opt) Some of the string-resources are good as unisex right now, is there any option to avoid copying those resources to the 2 new gender-dependent files and just add a default behavior of "if you don't find a string resource at values-he-male search for it in values-he"?
Thanks in advance!
Re'em
Same question for me. I plan to have (in addition to the default string.xml in English) iw (for male) and iw_fe (for female).
When the user selects his/her gender, I will change the locale (Set Locale programmatically )
As for using default values in Hebrew, I am still clueless. For now I will simply copy the Hebrew XML and change the required entries, leaving all the rest intact.
HTH
Noam

Skip suggestion string value from Android EditText

I have an Android EditText with suggestions enabled. My goal is not to disable suggestion (since i'm able to do that), but to skip some string values from them.
For example, suppose that i'd like to skip 'hello' word.
If i write 'he' in the EditText, my suggestions list shouldn't contain 'hello' since it's a string that has to be skipped. Is it possible?
Hope i explained myself, thanks

android edittext limit to text and numbers

I am creating an android application. The first thing I'm creating is a login activity. I am trying to limit the username edittext just to text/numbers only (no special characters). Is there a way to adjust this in the xml file?
I dont think you can limit the characters from xml. You could always use a InputFilter, but specifically android provides UsernameFilterGeneric to filter valid user names. You could also use UsernameFilterGMail
As you already use in java Regular expression.called the same class here for checking for particular field.
let me know if you want some more if you didn't know about the RE.

Android: converting between Strings, SpannedStrings and Spannablestrings

I have a string resource called "foo". It may be a simple string... or it may contain HTML. This may change over time: I should be able to box it up as at least a SpannableString immediately upon reading whether it's HTML or not (but how??)
I want to get that raw CharSequence and first be able to display it as-is (the exact characters, not Android's "interpretation" of it). Right now I can't do that... toString() decides to rip out the parts it doesn't think I want to see.
I'd then like to be able to create a SpannableString from this and other Strings or SpannableStrings via concatenation using some method (none of the normal ones work). I'd like to then use that SpannableString to display the HTML-formatted text in a TextView.
This shouldn't be difficult, but clearly I'm not doing it right (there's very little info out there about this that I've found so far). Surely there is a way to accurately interconvert between between Strings, SpannedStrings and even Spannablestrings, without losing the markups along the way?
Note that I've already played with the somewhat broken Linkify, but I want better control over the process (no dangling unformatted "/"s, proper hrefs, etc.) I can get this all to work IF I stay in HTML at all steps, though I can't concatenate anything.
Edit 1: I've learned I can use the following to always ensure I get my raw string (instead of whatever Android decides it thinks the CharSequence really is). Nice... now, how to coax this into a SpannableString?
<string name="foo"><![CDATA[
<b>Some bold</b>
]]>
</string>
Edit 2: Not sure why this didn't work earlier, but... if foo1 and foo2 are strings marked up as above (as CDATA), then one can apparently do this:
String foo1 = (String)getResources().getText(R.string.foo1);
String foo2 = (String)getResources().getText(R.string.foo2);
SpannedString bar = new SpannedString(Html.fromHtml(foo1+foo2));
Curious: is there a more straightforward solution than this? Is this CDATA business actually necessary? It seems convoluted (but not as convoluted as never quite knowing what the resource type will be... String, Spannable, etc.)
I had the same problem. There are two solutions according to Google API Guides.
First is to escape < mark with < in the string resource. Unfortunately, String conversion removes the tag in the background.
Second is to use Format Strings instead of XML/HTML tags. It seems simpler, faster, and evades hidden conversion problems. getString(resource, ...) works like a printf(string, ...) here.
Both work and require some code to replace given part of the string anyway (handle tags or format strings). Enjoy! =)
It appears there isn't a more straightforward way to accomplish this.

Categories

Resources