I tried to linkify an email address in my Android app, but it didn't work.
Method 1:
<TextView
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/email_address"
android:autoLink="email"/>
Method 2:
Linkify.addLinks((TextView)view.findViewById(R.id.email), Linkify.EMAIL_ADDRESSES);
I got "That action is not currently supported" using both methods. Is it a bug? Or I just can't try it out in a
Method 1 is sufficient.
If Android does recognize and "linkify" the email address but you receive an "action is not currently supported" message when you press it in the emulator, ensure that you have configured an email address in the Email app.
Once your email address is configured, pressing one of these links should jump straight to an email composition Activity.
use both methods for Linkify email address.as
TextView textView = (TextView)findViewById(R.id.email);
Linkify.addLinks(textView, Linkify.EMAIL_ADDRESSES);
and in Layout xml:
<TextView
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/email_address"
android:autoLink="email"/>
Related
I am building a registration page for a carpool app and I would like to only have a school email address used in the registration. How to input #csus.edu email into Android Studio app?
Currently I have:
<TextView
android:layout_width="wrap_content"
android:text="Email"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/etEmail"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content" />
Don't let them type it, and don't make it appear in the input box.
Something like:
Name: [text box] #csus.edu
so in this case, "Name:" and "#csus.edu" are both labels.
Client side validation. Just Substring whatever they enter
String end = EmailInput.substring(EmailInput.length() - 9, EmailInput.length());
boolean isValid = end.equals("#csus.edu);
That being said, I also agree with ergonaut in that save the user the time and trouble by not giving the option to enter a wrong email.
I am developing an accessible android application where people would be using Explore by Touch and TalkBack accessibility services to use my application.
This is my Android XML code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/forename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_marginLeft="15dip"
android:textSize="20sp"
android:text="#string/forenameText"
android:contentDescription="#null"/>
<EditText
android:id="#+id/EditTextForename"
android:layout_width="285dp"
android:layout_height="65dp"
android:layout_marginTop="10dip"
android:layout_marginLeft="15dip"
android:hint="#string/forenameHint"
android:inputType="textPersonName"
android:lines="1"
android:singleLine="true"
android:textSize="20sp" >
</EditText>
</LinearLayout>
strings.xml
<string name="forenameText">Forename</string>
<string name="forenameHint">Enter your forename here</string>
TextView displays the title "Forename" and EditText allows me to enter some details in the form field. The problem I have is that when I
drag my finger across the screen by using Explore by Touch, TalkBack picks up the title of the TextView and announces it aloud as "Forename". I want the TextView to only display text and not provide any audible feedback.
I have set contentDescription to #null as you can see from the code above, but TalkBack still announces "Forename" when my finger is located over the
TextView.
I have also tried setting contentDescription in my Java class:
TextView forename=(TextView)findViewById(R.id.forename);
forename.setContentDescription("");
However, I still get the same problem. Is there any other way to set contentDescription to null/empty and prevent TalkBack from announcing it aloud?
Java code:
public class MainActivity extends Activity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View forename = findViewById(R.id.forename);
forename.setAccessibilityDelegate(new AccessibilityDelegate() {
public boolean performAccessibilityAction (View host, int action, Bundle args){
return true;
}
});
}
}
Since API 16, Android introduced the following:
android:importantForAccessibility="no"
or
setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO)
Which allows developers to disable talkback all together for certain views.
http://developer.android.com/reference/android/view/View.html
For better backwards compatibility:
ViewCompat.setImportantForAccessibility(
decorativeTextView,
ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO);
I was trying to do the same today, and was able to set an 'empty' contentDescription on a TextView like so (using a non-breaking whitespace):
decorativeTextView.setContentDescription("\u00A0");
now TalkBack doesn't say anything for that TextView.
but I agree with Nick about leaving the label as readable in your case, because hint is only read for empty EditTexts.
Why do you not want the TextView to speak "forename"? It is being used as a label for the EditText. Once the user has entered some text the hint "enter your forename here" would no longer be spoken - as far as I know - so the TextView given the user some context for the EditText.
Similarly the announcement of "editbox" gives the user the role of the EditText control. While "form field" might be better it would not be the same behavior as in other apps and in the OS.
I had a similar problem. I eventually solved it by using the setAccessibilityDelegate method and overriding View.AccessibilityDelegate's performAccessibilityAction method.
try this:
View forename = findViewById(R.id.forename);
forename.setAccessibilityDelegate(new AccessibilityDelegate() {
public boolean performAccessibilityAction (View host, int action, Bundle args){
return true;
}
});
I had the same problem, and the only thing that worked for me was android:contentDescription=" " (white space).
In my Android app, I have a TextView. The text can contain links. This is an example of a text:
This is just a test. Click the following link http://www.google.com to visit Google.
Note that the text is not in HTML; it will be just a regular text.
I want to do something like textView.parseLinks(), then in the TextView, http://www.google.com will be hyper-linked and clickable to open up the page.
Is this possible?
Thanks
Try and include the following in the TextView definition in XML file:
<TextView
...
android:autoLink="web"/>
The docs of android:autoLink say:
Controls whether links such as urls and email addresses are automatically found and converted to clickable links
So for automatically finding links, the above may help. Try and see.
Something like this should work.
TextView tv = (TextView) findViewById(R.id.textView1);
String text = "This is just a test. Click this link here Google to visit google.";
tv.setMovementMethod(LinkMovementMethod.getInstance());
tv.setText(Html.fromHtml(text));
<TextView
...
android:autoLink="..."/>
//set ... by web|email|none|phone|map|all according to your need
// to change link color add below line
android:textColorLink="#color/yourcolor"
try this..it is working for me
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:text="click here http://www.google.com/"/>
Simple way to make selecting URL and Phone numbers in TextView:
TextView textView = (TextView)findViewById(R.id.textView1);
textView.setText("some url is www.google.com phone 7504567890 another url lkgndflg.com ");
Linkify.addLinks(textView, Linkify.WEB_URLS | Linkify.PHONE_NUMBERS);
I have a TextView:
<TextView
android:text="Contact details go here"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tvContactDetails"
android:autoLink="email" />
I then put an e-mail address in (I'm using Monodroid, but it doesn't really make any difference here):
TextView tvContactDetails = FindViewById(Resource.Id.tvContactDetails)
tvContactDetails.Text = sEmail;
If I give it an e-mail address like joe#bloggs.com it's fine. But when I give it kevin.o'donnel#abc.com it only hyperlinks donnel#abc.com. How can I get it to recognise apostrophes as part of the e-mail address?
After a while of searching and trying things I found a solution which worked for me at:
TextView to send email when clicked
TextView now looks like this:
<TextView
android:text="Contact details go here"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tvContactDetails"/>
(autoLink taken out)
The code now looks like this:
TextView tvContactDetails = FindViewById(Resource.Id.tvContactDetails)
string sHtmlEmail = "" + sEmail + "";
tvContactDetails.TextFormatted = Html.FromHtml(sHtmlEmail);
tvContactDetails.MovementMethod = Android.Text.Method.LinkMovementMethod.Instance;
Thanks for the suggestions though.
I am developing an accessible android application where people would be using Explore by Touch and TalkBack accessibility services to use my application.
This is my Android XML code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/forename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_marginLeft="15dip"
android:textSize="20sp"
android:text="#string/forenameText"
android:contentDescription="#null"/>
<EditText
android:id="#+id/EditTextForename"
android:layout_width="285dp"
android:layout_height="65dp"
android:layout_marginTop="10dip"
android:layout_marginLeft="15dip"
android:hint="#string/forenameHint"
android:inputType="textPersonName"
android:lines="1"
android:singleLine="true"
android:textSize="20sp" >
</EditText>
</LinearLayout>
strings.xml
<string name="forenameText">Forename</string>
<string name="forenameHint">Enter your forename here</string>
TextView displays the title "Forename" and EditText allows me to enter some details in the form field. The problem I have is that when I
drag my finger across the screen by using Explore by Touch, TalkBack picks up the title of the TextView and announces it aloud as "Forename". I want the TextView to only display text and not provide any audible feedback.
I have set contentDescription to #null as you can see from the code above, but TalkBack still announces "Forename" when my finger is located over the
TextView.
I have also tried setting contentDescription in my Java class:
TextView forename=(TextView)findViewById(R.id.forename);
forename.setContentDescription("");
However, I still get the same problem. Is there any other way to set contentDescription to null/empty and prevent TalkBack from announcing it aloud?
Java code:
public class MainActivity extends Activity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View forename = findViewById(R.id.forename);
forename.setAccessibilityDelegate(new AccessibilityDelegate() {
public boolean performAccessibilityAction (View host, int action, Bundle args){
return true;
}
});
}
}
Since API 16, Android introduced the following:
android:importantForAccessibility="no"
or
setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO)
Which allows developers to disable talkback all together for certain views.
http://developer.android.com/reference/android/view/View.html
For better backwards compatibility:
ViewCompat.setImportantForAccessibility(
decorativeTextView,
ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO);
I was trying to do the same today, and was able to set an 'empty' contentDescription on a TextView like so (using a non-breaking whitespace):
decorativeTextView.setContentDescription("\u00A0");
now TalkBack doesn't say anything for that TextView.
but I agree with Nick about leaving the label as readable in your case, because hint is only read for empty EditTexts.
Why do you not want the TextView to speak "forename"? It is being used as a label for the EditText. Once the user has entered some text the hint "enter your forename here" would no longer be spoken - as far as I know - so the TextView given the user some context for the EditText.
Similarly the announcement of "editbox" gives the user the role of the EditText control. While "form field" might be better it would not be the same behavior as in other apps and in the OS.
I had a similar problem. I eventually solved it by using the setAccessibilityDelegate method and overriding View.AccessibilityDelegate's performAccessibilityAction method.
try this:
View forename = findViewById(R.id.forename);
forename.setAccessibilityDelegate(new AccessibilityDelegate() {
public boolean performAccessibilityAction (View host, int action, Bundle args){
return true;
}
});
I had the same problem, and the only thing that worked for me was android:contentDescription=" " (white space).