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

Which Activity inflated CustomAdapter?
Secure support of HTTPS in an Android app with untrusted certificates
android: webview inside dialog or popup
Android - lost previous drawing on making a paint App
Android - unregisterReceiver concept in detail?
Google Play Store warning about fewer devices supported by updated APK
Differences between Push functions in RIM OS (BIS), IOS and android
How to show the lockscreen after tapping a button and closing the activity?
Some code in Android APIDemos Sensors.java puzzle me
Android JNI APK Packing
Android/Mobile Webkit CSS Background-Attachment:Fixed Not Working?
How can I make sure Android Beam doesn't start a new instance of my 'singleTop' activity?
Android Unable to resolve host
couldn't find import for class android.database.Cursor in AIDL file
Putting settings menu to Home Widget
Android Emulator Contacts Manager source code?

Categories

HOME
asp.net-web-api
eclipse
microsoftgraph
string
jmeter
ecmascript-6
css3
rdbms
angular-formly
depth
toolbox
camera
vscode-extensions
replace
tivoli
alsa
vxml
crystal-reports-2013
azure-container-service
title
elasticsearch-5
bing-maps
openstreetmap
enthought
android-securityexception
php-5.6
spring-social
radgridview
comsol
magnetic-cards
entitymanager
symfony-2.8
job-scheduling
sigma.js
lilypond
dataflow-diagram
imageresizer
data.stackexchange.com
licensing
angularjs-components
ms-access-2003
rpgle
cart
hard-drive
joomla2.5
indy10
least-squares
xajax
nohup
recurrent-neural-network
xv6
vmware-fusion
naming
importerror
apache-directory
phpdbg
jquery-ui-draggable
page-replacement
payara-micro
check-mk
reshape
rsa-archer-grc
node-request
grails-plugin
custom-lists
actor-platform
resourcemanager
lean
observablecollection
kango-framework
nss
gcloud-ruby
hadoop-partitioning
lz77
highland.js
spring-retry
dynatree
qt5.2
toolkit
slash
evolus-pencil
ember-cli-rails
atoi
vacuum
baasbox
jsvc
entity-framework-4.3
mass-assignment
variadic-templates
ignite-ui
authlogic
extjs2
menubar
accesscontrolexception
ecslidingviewcontroller
poker
android-icons
pdfviewer
mkv
predicatebuilder
box2d-iphone
flex-mobile
htdocs
ruby-1.8
pos-for-.net
software-lifecycle
flvplayback
idatareader

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