android


How do we set color to an underline for text in textView programatically


I am new to Android. I created a table and set textView inside it .I would like to give underline to the text I input in textView. I created an underline by the following code :
SpannableString content=new SpannableString(Regions)
content.setSpan(new UnderlineSpan(),0,Regions.length(),0);
where region is the string containing text.
Can anyone tell me how do we set a color based on our choice to the underline?
I faced the same issue, there is no straight way to do it. You can check my solution below :
Modify the text view as below in your layout :
<TextView
android:id="#+id/residential_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#null"
android:background="#drawable/only_one_bottom_line"
android:layout_margin="12dp"
android:paddingBottom="4dp"
android:text="test string"
android:textColor="#drawable/re_option_highlight"
android:textSize="11sp" />
only_one_bottom_line.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<solid android:color="#android:color/transparent" />
</shape>
</item>
<item android:top="-4dp" android:right="-4dp" android:left="-4dp">
<shape>
<solid android:color="#android:color/transparent"/>
<stroke
android:width="3dp"
android:color="#0093dd" >
</stroke>
</shape>
</item>
</layer-list>
This background have only one bottom line, and you can change the color from #00 93dd to any color you want. This solution is more easier to implement than creating a custom text view and making hell lot of changes there.
To give color to perticuler string you can use Spannable
String s="your text";
SpannableString ss= new SpannableString(s);
ss.setSpan(new ForegroundColorSpan(Color.GREEN), 0, 5, 0);
tv.setText(ss);

Related Links

Scaling getProjection().getVisibleRegion()
Last item in recyclerview (inside a nestedscrollview) is cut, landscape orientation cuts the viewpager
Android Fragment, how to use both v4 and app.fragment in same viewpager
How to getRotation(); in non-activity class
Manage Threads on Rxjava
uploading an image to firebase storage fails
View getting null in onActivityResult()
Database Firebase + RecyclerView
android make layout scrollable when the keyboard appears [duplicate]
PackageManager - fast way (batch way) to retrieve a lot of infos at once
I cannot install android sdk on AWS linux T.T
How to add a view in between the html tags in webview android
Android ExpandableListView getChildView makes a mess of data
Encrypting Realm Database
TTS causing IllegalArgumentException:Invalid int: “OS” during onInit in some Samsung devices with android api 23
Android Ptrace Operation not Permitted

Categories

HOME
fabricjs
fuelux
linkedin
ggplot2
themes
rendering
big-o
web-hosting
nuget-package
jtextpane
discrete-mathematics
32bit-64bit
mod-security
resultset
dynatrace
enterprise-architect
forgot-password
swagger-2.0
asp.net-core-webapi
qliksense
mount
siri
motion-detection
mailkit
sharepoint-workflow
zoomify
xdocreport
typesafe-config
preloader
dapper-simplecrud
procfile
fwrite
lampp
manova
corruption
appdomain
colorbar
filehandle
rxtx
restore
juice-ui
custom-lists
adafruit
spring-cloud-feign
hclust
cassia
lua-telegram-bot
deep
boost-serialization
httpruntime.cache
design-principles
user-management
vhosts
themoviedb-api
include-guards
video-player
.bash-profile
rpart
atoi
dulwich
vacuum
branch-and-bound
mirror
avahi
procedural-programming
exceldatareader
angular-gettext
uncaught-typeerror
administration
metatrader5
raygun
winginx
paste
websphere-esb
synapse
clickbank
rfc5322
jeromq
script#
facebook-timeline
traceability
saleslogix
predicatebuilder
jsr286
fitbounds
xcelsius
mysql-error-1205
pylucene
cgbitmapcontextcreate
unattended-processing
ie-compatibility-mode
ajax-polling
django-piston
product-management
httpcookie
image-capture

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App