I have textview in which multiple links are shown, the text is dynamic.
I have added following to textview
android:autoLink="all"
android:textColorLink="#color/selector_autolink_textcolor"
This makes all links in textview show a different color and show click color, but on click of textview all the links in textview show selected color, this confuses the user as he cannot identify what he's clicking.
How can I only highlight/show press-state of a single link when pressed.
I have two approaches for you to solve this problem.
First Approach:- This one is quite simple. You can use different TextView to display hyperlinks and display the links. On clicking them you can get different selector color
Second Approach:- Use can use Spannable concept in Android to achieve this. Break the string into different part to show different hyper links. You can achieve the different color slector based upon user click. You can follow this example more from here (see try Spannable part) Change the text color of a single ClickableSpan when pressed without affecting other ClickableSpans in the same TextView
Related
I have a text that is sometimes too high and at times one word.
How to put the text in this TextView so that the first two lines are located around the specified spacing?
Should this be done by 2 TextView?
If yes, how can I figure out how much text is placed on the top two lines?
You can use a Spannable to add customizations to a string inside a TextView.
The styling android blog has an excellent post about it: https://blog.stylingandroid.com/introduction-to-spans/
But looking to your print, it seems that the first row will always have a style and the rest another. With this, using two TextViews and customizing the view directly is a better option for code and performance.
Yesterday I asked a question about the TextView. I read and I see that it's very difficult to understand. So, I'm sorry.
Now I explain better my problem:
I try to personalize my TextView. I tried two different things:
I use photoshop, I made an image text and I use it as a drawable. The image re-sized isn't with right quality
I try to use the text of TextView, but I can't change the family of the text (the app crashed). Then I don't know how to set gradient as text color and border in the text.
What can I do?
Edit: yes! For the point 1 I use an ImageView inside of TextView. In point 2 I use TextView. I have problem in both situation!
I think to customize textview (any view) you have to implement your own custom view by creating your custom class.
Here is link for custom text view,i hope i will find it useful
http://www.jayway.com/2012/06/25/creating-custom-android-views-part-1-extending-standard-views-and-adding-new-xml-attributes/
I want to display a text where certain words lead to other activities within the application.
Is there a more convenient way to achieve it other than having a bunch of TextViews along with buttons (with the clickable words and a transparent background) side by side?
Just the bunch of TextViews and their onClick(s) should do, you wouldn't need the Buttons..
You can take a look at the Linkify class, that searches for some predefined links in the text such as phone numbers, e-mail addresses and web links and automatically makes them clickable and leading to the corresponding activities when clicked. I think there is a possibility of adding your own pattern to recognize words in the text and bind them to activities you want to be used for those words. Hope this helps.
Please check both of the links
http://blog.elsdoerfer.name/2009/10/29/clickable-urls-in-android-textviews/
handle textview link click in my android app
I like to recreate the behaviour of the textview containing the message of a user in the g+-app in my android project. To be exact:
- on click on a link the link is visually selected (blue selector) and will open up in the browser
- on click on normal text the whole list item is selected
The main problem I have, is, that every approach I tried to make links clickable (via xml and autolink=web, or in code) ends up, that the link opens up in a browser on click, but when I touch normal text in this textview the item is not selected (no selector is visible).
I read many threads about this issue, but all the solutions, like add setFocusable(false), etc. doesn't work for me.
So I want to ask, if there is any tutorial, how to or example, where I can see how this things work, or do you have any idea how I can get it to work?
Thanks! :)
if you have email id in textview use below code..
TextView email = (TextView)findViewById(R.id.TextView04);
email.setText("sasd asd#gmai.com sadasd");
email.setLinkTextColor(Color.WHITE);
Linkify.addLinks(email,Linkify.EMAIL_ADDRESSES);
if you have url in textview use below code...
TextView tv = (TextView)findViewById(R.id.TextView04);
tv.setText("sasd https://asd.com sadasd");
tv.setLinkTextColor(Color.WHITE);
Linkify.addLinks(tv,Linkify.WEB_URLS);
Is it Possible to Display some text say a story, in an ANDROID app which also enables the user to select some text and perform some operations on that text..
the main idea is to display some text and when the user selects some text(a word or a sentence) i need to get that text for some further operation on that text.
we cant use text view as you cant select text in textview,and we cant use editview because the user should not be able to edit the contents of the text.
Why not display the text in a WebView and enable text selection?
It works pretty well in CodePad, which is open source so you can have a look at the code here.
My first try would be to display this text in a normal TextView. Then I would provide two or three buttons to implement the selection of a part of the text. For example 1 Button to start and end selection and 2 Buttons with arrows for increasing/decreasing the part of the selection.
To highlight the part of the text which is selected, I would for example color this part of the text in a different color.
Coloring of text can be either done by using Spannable or the HTML class.