• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7611
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 607
11
Android Python Open BSD VI Editor Slackware
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic