• 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
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

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..

 
Bartender
Posts: 7488
171
  • 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: 600
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
 
It was the best of times. It was the worst of times. It was a tiny ad.
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic