I'm developing a Nativescript app, and in some devices the hint is bigger than the input, IOS add three dots at the end (...) like an ellipsis, but android only cut off the hint.
I tried the following code:
let shareInput: TextField = this.page.getViewById<TextField>('share-input');
shareInput.android.setEllipsize("end");
I'm getting an error like this:
java.lang.Exception: Failed resolving method setEllipsize on class
android.widget.EditText
I red some android issues and tried to use setSingleLine method but it does not work.
Any help is welcomed.
So this method is what you need (and are using :) - https://developer.android.com/reference/android/widget/EditText.html#setEllipsize(android.text.TextUtils.TruncateAt)
your argument is incorrect, it isn't expecting a string but an ENUM.
So try setEllipsize(android.text.TextUtils.TruncateAt.END)
And if you're going to be setting this on multiple fields I would add a var for the TruncateAt enum like const TruncateAt = android.test.TextUtils.TruncaeAT then just use that const/var in the argument like (TruncateAt.END) to save on repeating yourself.
Related
I created a small test android app which has a text box and a button and am able to build this and launch on a real device (android) using WebDriverIO.
However, when I try to select elements I can't locate them.
Example: the text field has the following properties:
id: editTextTextPersonName
input type: textPersonName
contentDescription: #string/fldName1 (which is the string "helpme" in the xml)
Using UIAutomatorViewer I can see the field has the following:
resouce-id** = com.example.myfirstapp:id/editTextTextPersonName
package = android.widget.EditText
class = android.widget.EditText
content-desc: helpme
However, I cannot locate this using WebDriverIO.
I have tried
$('~helpme').setValue('test')
but that doesn't work.
Does anyone have any suggestions?
To be honest, you're doing everything correct. AFAIK there is an issue with the $('~helpme') selector within WebdriverIO/Appium not being able to find the correct element / failing on Android.
What I did in the past, especially if I needed to use cross-platform locators, was that I created a method like this
const locatorStrategy = (selector: string): string => {
return driver.isIOS ? `id=${selector}` : `//*[#content-desc="${selector}"]`;
};
which could be used like this
$(locatorStrategy('input-email'));
You can also validate your selector with Appium Inspector. This is how Appium Inspector looks like
You can then press this button
then select XPATH and add this //*[#content-desc="input-email"] selector
hit Search which will lead to this
So in your case, if you would use or something like above or just this
$('//*[#content-desc="helpme"]').setValue('test')
then it should work
I know how to do this on Java.
I copied and paste the code from Java to Kotlin and Android Studio changed to this:
auth_password_text.setInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD)
But I'm receiving a message (grey not yellow like warning)
I search and found only java and react native answer but not was the best/right way to do this in Kotlin.
Thank you in advance!
In Kotlin you can set some properties accessing directly variable instead of calling setter method, that's the meaning of the warning you are getting.
You can remove warning like this:
auth_password_text.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
For any warning or suggestion reported by the IDE, you can press Alt-Enter, and in most cases (including this one) the IDE will suggest a quickfix that will automatically apply the suggested change.
In this case, it will change the call of a Java setter to a Kotlin property access:
auth_password_text.inputType = ...
I'm trying to replace Resources.GetColor with ContextCompat.GetColor but the last one does not return a color and I don't get what should i use instead of Resources.GetColor(which became deprecated from API 23). Can anyone help me (see below what I want to achieve)?
Button.SetBackgroundColor(ContextCompat.GetColor(this, Resource.Color.LightRed));
Note that I use Xamarin, but if you have answer in java I can easily adapt it.
Thank you!
ContextCompat just returns an integer representation of your color. You need to convert it to an Android color by splitting its RGB parts up. Use something like this
using Android.Graphics;
public static Color GetColorFromInteger(int color)
{
return Color.Rgb(Color.GetRedComponent(color), Color.GetGreenComponent(color), Color.GetBlueComponent(color));
}
and in your method
btn.SetBackgroundColor(GetColorFromInteger(ContextCompat.GetColor(this, Resource.Color.LightRed);
I had the same problem I think - and resolved it by adding the annotation #SuppressWarnings("ResourceAsColor") on top of the method.
The reason is that, in my opinion, Lint does not recognise the new API at this moment, even though it's valid. Both methods return an integer that represents a resolved color. In my tests Resources.GetColor() and ContextCompat.GetColor() return the same value. However, when using the latter I get an error in Android Studio saying:
Should pass resolved color instead of resource id here: `getResources().getColor(titleColor)`
...which does not make sense, because I AM passing a resolved color. It's just an int, so how can I be wrong... So in conclusion, I think suppressing the Lint Error is a valid way to handle the situation at the moment.
If you disagree please raise your voice, I'd be interested.
How to use inputfilter for CNIC i.e #####-#######-# ? Please help me.. I am new to Android and I dont know how to use it?
How to mask input? I went through various sites but couldn't find solution. I am so confused.
Have you tried using Masked EditText ? This is what you want ... :)
If you want a numeric keyboard instead of alphabetical, then comment the following lineof code:
this.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
in the file MaskedEditText.java. Now setting android:inputType = "numeric" will work.
) You can also try the fork of Masked EditText. It's derived but with works with Gradle, has some bugfixes, an example project, and a little bit another behavior :-)
The behavior is also changed:
You can set the flag and the hint will be always visible.
Your pattern is invisible initially and grows automatically as soon, as you type. For instance, in the beginning, it is: "+7(", then you type '999' and it shows you "+7(999)" with another brace. In the original library, AFAIK it works like: "+7( ) - - ", then you type '999' and it transforms into "+7(999) - - " and so on.
I want to be able to set the text of buttons using the strings xml file. I have this code;
Button playVid = (Button)this.findViewById(R.id.vidbutton1);
playVid.SetText(this.getApplicationContext().getString(R.string.play_video));
And this xml
<string name="play_video">Play Video</string>
But I get the compile
error: cannot resolve method settext(java.lang.string)
I am using Android Studio. Everywhere I have read suggest that you can use strings to set text (makes sense, right?), so I am very confused.
This also will not work:
playVid.SetText("Test");
Bug in AS?
Mind your casing. Use setText() instead of SetText().
Also there's an overload setText(int) that takes in a resource id. You can use it to set a value from resources without using getString() to obtain it yourself first.
Methods in Java usually start with a lower-case letter. Maybe that's what your problem is here.
Try playVid.setText("Test"); instead of playVid.SetText("Test");
This works perfectly fine:
Button button = (Button) findViewById(R.id.some_button);
button.setText(R.string.hello_world);
Make sure you imports are correct ;)