• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

How To Change the Background (not just Background Color) of TextViews programmatically?

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a resource file that creates a shape:


I want to change the Background of various TextViews at run-time programatically.

I've tried various ways, using setBackground and setBackgroundResouerce together with things like getDrawable
e.g.
and many others, but I just can't come up with a version that works.

I know how to change the backgroundColor but this only gives me a single color for the whole of the TextView.  Ideally I'd like to be able to use the shape I've created in the XML file which has a border, rounded corners as well as the main background color.

Can someone please help?  I feel like it should be something simple, but none of the searches I've done have produced the answer to this specific scenario..

 
Saloon Keeper
Posts: 5917
152
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know for sure, but I wouldn't be surprised if TextView doesn't support anything in the background beyond the color. You could try using a View with the desired characteristics, and then putting the TextView on top of that.
 
Ged Mead
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:I don't know for sure, but I wouldn't be surprised if TextView doesn't support anything in the background beyond the color. You could try using a View with the desired characteristics, and then putting the TextView on top of that.


Ah!  That would explain why even after an exhaustive search I couldn't find any mention of how to do this!
Thanks
 
Ranch Hand
Posts: 507
10
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ged Mead wrote:

Tim Moores wrote:I don't know for sure, but I wouldn't be surprised if TextView doesn't support anything in the background beyond the color. You could try using a View with the desired characteristics, and then putting the TextView on top of that.


Ah!  That would explain why even after an exhaustive search I couldn't find any mention of how to do this!
Thanks


I guess you are looking for  "background tint". Should work to change resource programmatically in your Adapters
 
I AM MIGHTY! Especially when I hold this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!