- Удалить подчеркивание из ссылок в TextView — Android
- ОТВЕТЫ
- Ответ 1
- Ответ 2
- Ответ 3
- Ответ 4
- Ответ 5
- Ответ 6
- Ответ 7
- Ответ 8
- Ответ 9
- Ответ 10
- Ответ 11
- Удалить подчеркивание из ссылок в TextView-Android
- 10 ответов:
- Category: TextView Hyperlink – Change Color and Remove Underline
- TextView HyperLink – Change Color and Remove Underline
- Remove underline from links in TextView – Android
Удалить подчеркивание из ссылок в TextView — Android
Я использую два textview для отображения ссылок из базы данных, мне удалось изменить цвета ссылок, но я хочу удалить подчеркивание
Могу ли я сделать это из XML или кода?
ОТВЕТЫ
Ответ 1
Вы можете сделать это в коде, найдя и заменив экземпляры URLSpan версиями, которые не подчеркивают. После вызова Linkify.addLinks() вызовите функцию stripUnderlines() , вставленную ниже на каждый из ваших TextView s:
Для этого требуется настраиваемая версия URLSpan, которая не включает свойство подчеркивания TextPaint:
Ответ 2
С учетом textView и содержимого:
Вот краткий способ удаления подчеркиваний из гиперссылок:
Это основано на подходе, предложенном robUx4.
Чтобы сделать ссылку кликабельной, вам также нужно позвонить:
Ответ 3
UnderlineSpan уже существует, но может устанавливать только подчеркивание.
Другим решением является добавление без подчеркивания для каждого существующего URLSpan . Таким образом, состояние подчеркивания отключается непосредственно перед покраской. Таким образом, вы сохраняете свои URLSpan (возможно, пользовательские) классы и все остальные стили, заданные в другом месте.
Вот как вы установили его, не удаляя существующий объект URLSpan:
Ответ 4
Всякий раз, попробуйте удалить подчеркивание URL с помощью spannable am, я предлагаю только следующие вещи:
1 > Создание пользовательского класса:
Для этого требуется настраиваемая версия URLSpan, которая не включает свойство подчеркивания TextPaint
2 > setSpan со спанимым текстом:
Здесь spannableText находится объект SpannableString.
Ответ 5
Я реализовал решение, которое, на мой взгляд, более элегантно. Я создал пользовательский TextView . Таким образом, вам не нужно выполнять дополнительный код для каждого TextView с гиперссылками.
И код для UrlSpanNoUnderline:
Ответ 6
Если вы используете свойство autolink Textview и хотите удалить подчеркивания, вы можете использовать его:
Во-первых, расширьте UnderlineSpan и удалите подчеркивание:
Во-вторых, создайте и создайте экземпляр NoUnderlineSpan, создайте Spannable из текста String и установите span на spannable:
Ответ 7
Если вы просто хотите текст и не беспокоитесь о ссылке URL
Это будет STRIP ссылка, но ХРАНИТЕ текст
дополнительных классов не требуется
Ответ 8
Назовите это так
Appcontroller — это мой класс приложения, где я помещаю этот метод, чтобы я мог получить к нему доступ из любого места
Ответ 9
Для пользователей Xamarin, которые находят этот пост, вот как я заставил его работать:
Создайте пользовательский класс span для обработки подчеркивания.
class URLSpanNoUnderline: URLSpan
Создайте метод расширения, чтобы найти все диапазоны URL-адресов и заменить их нашими пользовательскими интервалами.
Ответ 10
Ответ 11
Подчеркивание в android: autoLink можно удалить с помощью android: textAllCaps = «true» и android: textIsSelectable = «false»
Источник
Удалить подчеркивание из ссылок в TextView-Android
Я использую два textview для отображения ссылок из базы данных мне удалось изменить цвета ссылок, но я хочу удалить подчеркивание
могу ли я сделать это из XML или кода ?
10 ответов:
вы можете сделать это в коде, найти и заменить URLSpan экземпляров с версиями, которые не подчеркивают. После того, как вы позвоните Linkify.addLinks() вызов функции stripUnderlines() вставлено ниже на каждом из ваших TextView s:
для этого требуется настроенная версия URLSpan, которая не включает свойство TextPaint «underline»:
учитывая textView и содержание:
вот краткий способ удалить подчеркивания из гиперссылок:
это основано на подходе, предложенном robUx4.
для того, чтобы сделать ссылки кликабельными вам также нужно позвонить:
UnderlineSpan уже существует, но может только установить подчеркивание.
другое решение состоит в том, чтобы добавить без подчеркивания промежуток на каждом существующем URLSpan . Таким образом, состояние подчеркивания отключается непосредственно перед рисованием. Таким образом, вы держите ваш URLSpan (возможно, пользовательские) классы и все другие стили, установленные в другом месте.
вот как вы устанавливаете его без удаления существующего объекта URLSpan:
всякий раз, когда, попробуйте удалить подчеркивание URL-адресом С spannable я предлагаю только эти вещи :
1> создание пользовательского класса :
для этого требуется специальная версия URLSpan который не включает свойство TextPaint «подчеркивание»
2> setSpan с spannable текстом:
здесь spannableText является объектом SpannableString.
я реализовал решение, которое, на мой взгляд, более элегантно. Я сделал custom TextView . Таким образом, вам не нужно выполнять дополнительный код для каждого TextView с гиперссылками.
и код для UrlSpanNoUnderline:
Если вы используете свойство Textview autolink и хотите удалить подчеркивания, вы можете использовать его:
во-первых, расширить UnderlineSpan и удалить подчеркивание:
во-вторых, создайте и экземпляр NoUnderlineSpan, создайте Spannable из текста строки и установите span в spannable:
Источник
Category: TextView Hyperlink – Change Color and Remove Underline
Sometimes, we need to display hyperlink in textview.
This hyperlink can of following format:
admin is attending Alchemist Rocks.
Which will be seen in the web view as displayed below
How do we create such text in android textview ?
Follow the given steps and you will successfully create a textview whose links will be displayed as shown in the webview:
1. Create a textview in xml
2. In your activity, initialize the String and textview as given in the following code snippet
3. Run your project.
When you run your project, you will see a textview similar to the give figure:
Here, in the given figure, you will see the user names in blue color, which is just as we want……..
But, we dont need the underline. To remove underline
i. Create a new class named as URLSpanNoUnderline as shown in the given code snippet:
ii. Go to your activity and replace the code
by the following code snippet:
iii. then, add the given function in your activity:
Then, run your code, you will get the perfect textview as shown in the given screenshot:
How did the underline disappeared ? What did the given class and function do ?
Heres the explanation :
As you may already know, the TextView object has a property named android:autoLink that creates HTML or email links automatically. You also got properties to change link colors such as android:textColorLink and android:textColorHighlight. The only missing option many of us would like to have is a way to remove the underline under the link itself.
Sadly, removing the underline seems to be somewhat “hard” to achieve. So i had added the given a news class and a new function.
Источник
TextView HyperLink – Change Color and Remove Underline
Sometimes, we need to display hyperlink in textview.
This hyperlink can of following format:
admin is attending Alchemist Rocks.
Which will be seen in the web view as displayed below
How do we create such text in android textview ?
Follow the given steps and you will successfully create a textview whose links will be displayed as shown in the webview:
1. Create a textview in xml
2. In your activity, initialize the String and textview as given in the following code snippet
3. Run your project.
When you run your project, you will see a textview similar to the give figure:
Here, in the given figure, you will see the user names in blue color, which is just as we want……..
But, we dont need the underline. To remove underline
i. Create a new class named as URLSpanNoUnderline as shown in the given code snippet:
ii. Go to your activity and replace the code
by the following code snippet:
iii. then, add the given function in your activity:
Then, run your code, you will get the perfect textview as shown in the given screenshot:
How did the underline disappeared ? What did the given class and function do ?
Heres the explanation :
As you may already know, the TextView object has a property named android:autoLink that creates HTML or email links automatically. You also got properties to change link colors such as android:textColorLink and android:textColorHighlight. The only missing option many of us would like to have is a way to remove the underline under the link itself.
Sadly, removing the underline seems to be somewhat “hard” to achieve. So i had added the given a news class and a new function.
Источник
Remove underline from links in TextView – Android
Posted by: admin December 5, 2017 Leave a comment
I am using two textview to display links from database, I managed to change link colors but I want to remove the underline
Can I do that from XML or Code ?
You can do it in code by finding and replacing the URLSpan instances with versions that don’t underline. After you call Linkify.addLinks() , call the function stripUnderlines() pasted below on each of your TextView s:
This requires a customized version of URLSpan which doesn’t enable the TextPaint’s “underline” property:
Given a textView and content:
Here is a concise way to remove underlines from hyperlinks:
This is based on the approach suggested by robUx4.
In order to make the links clickable you also need to call:
UnderlineSpan already exists, but can only set the underline.
Another solution is to add a no underline span on each existing URLSpan . Thus the underline state is disabled just before painting. This way you keep your URLSpan (possibly custom) classes and all other styles set elsewhere.
Here is how you set it without removing the existing URLSpan object:
Whenever, try to remove URL underline with spannable am i suggest only these things :
1> Creating Custom class :
This requires a customized version of URLSpan which doesn’t enable the TextPaint’s “underline” property
2> setSpan with spannable text :
Here, spannableText is Object of SpannableString….
I’ve implemented a solution which, in my opinion, is more elegant. I’ve made a custom TextView . This way you don’t need to execute extra code for every TextView with hyperlinks.
And code for UrlSpanNoUnderline:
If you just want the text and don’t bother about the URL link
This will STRIP the link but KEEP the text
no additional classes required
If you are using Textview autolink property and you want to remove underlines you can use it:
First, extend UnderlineSpan and remove underline:
Second, create and instance of NoUnderlineSpan, create a Spannable from the String text and set the span to the spannable:
Underline in android:autoLink can be removed using android:textAllCaps=”true” and android:textIsSelectable=”false”
Here is My method
Call It like this
Appcontroller is my application class where i put this method so that i can access it from anywhere
Источник