I am designing an App, where there is TextView, and based on some check condition, I want to make links / phone numbers in the TextView clickable in Java side. Can I do this, I don't want to make it clickable by default which is done by setting in xml file
android:autoLink="all"
What I already tried:
Create regular TextView and don't set autoLink="all",
TextView myView =
(TextView)view.findViewById(R.id.thisIstheTextView);
myView .setLinksClickable(true);
also tried :
myView .setMovementMethod(LinkMovementMethod.getInstance());
None of the above Java code works, I don't want a predesigned xml TextView with autoLink enabled, I want to change the TextView behavior in Java code based on if () conditions. There is no error in my code, but I am not able to achieve what I want. Can you please share your knowledge. Thank you.
Use setAutoLinkMask (int mask).
The possible values that can be combined for mask are those defined for the Linkify class.
Linkify.addLinks(myView, Linkify.ALL);
Fixed the issue.
Related
Is it possible to change the android id of a view or any of their elements, such as an imageView based on some code? That is, verifying a variable such as a bool and having a different id depending on the value such as image_true and image_false.
I am working on an automation project with Appium and I need to be able to differentiate a success pop-up from an error pop-up. They are essentially the same component but the image is different depending on the state of it.
You can use View#setId with some positive integer as ids are basically integers
Your answer is not clear enough but it's possible to change it by #setId method of View. And consider this issue that changing the view id when runtime may cause errors inside the code if it is using that view by hardcoded id so it can't be found by those components anymore.
An alternative is to dynamically change tags using View#setTag which can accept strings. To access the view using tags, you can use findViewWithTag.
Sample code to access view using tag:
LinearLayout layout = findViewById(R.id.layout);
TextView textView = layout.findViewWithTag("someTag");
I'm currently working on a project where I'm supposed to use text with a glowing background , something like this
Any ideas ?
You have to use android:shadowColor, android:shadowDx,android:shadowDy & android:shadowRadius in TextView defination inside xml. Check this discussion How to make text glow?
As in the images shown below, is it possible to write code to write "to the power" in Android or Java?
Something like:
TextView t = (TextView) findViewById(R.id.text);
t.setText(Html.fromHtml("7<sup>2</sup>"));
According to Android documentation on their FAQ, you can always do this using a string resource, but if you do it on the fly you must make sure the TextView is using Spannable storage (always true if it's an EditText for example).
See Selecting, Highlighting, or Styling Portions of Text in the Android Common Tasks.
You can write HTML Code to show something like this.
I am making an app that has two EditText views, txtOne which is used for input, and txtTwo which is used for output. txtOne is editable, and txtTwo is not.
I am looking for a simple way to scale the font size of the text in these two views so that it always fits within the view without wrapping to a new line.
I have found a few implementations of this using custom views extending TextView, but they aren't fit for an EditText view, or use android.graphics.Paint, which is not what I am looking for.
Is there any way to check to see when text in an EditText view is wrapping? If so, then it would be easy enough to do something like:
if(txtOne.isWrappingText()) {
txtOne.setTextSize(txtOne.getTextSize() - 2);
}
Does anyone know of any way to detect this or an alternative solution?
I deleted my post
Basically the suggested code contained a TextWatcher for the EditText, this helped to answer the question. But the code itself was just wrong (I tested it meanwhile).
I suggest to read this question and answers because they adress the very same issue...
I can display the contents of a file in a TextView by adding the file under the raw folder and reading the file. It works fine. But all of the contents in the file look the same. I want to differentiate titles and the contents by introducing Font styles. Can anybody help?
What I understood from your question is that you want to apply different formatting to different parts of your text in TextView. But As I know, TextView doesn't supports multiple styles (formatting) (yet). Whatever the formatting you apply, will be applied to the whole text in TextView. To use different formatting, you can use the WebView.
Update:
This functionality is available for EditText (I saw it too late), see this link for details; http://developer.android.com/resources/faq/commontasks.html#selectingtext
You can use WebView instead as your text is static you can format it to create a htmlPage and then display it in webview something like this
WebView mView = (WebView) findViewById(R.id.help_text);
mView.loadUrl("file:///android_asset/help.html");
mView.getSettings().setSupportZoom(false);