java - Programatically setting TextView background -


i've defined background textview:

<?xml version="1.0" encoding="utf-8"?> <shape     xmlns:android="http://schemas.android.com/apk/res/android"     android:shape= "rectangle"  >     <solid android:color="#000"/>     <stroke android:width="1dp"  android:color="#ff9"/> </shape> 

now i'm trying set textview programmatically:

textview.setbackground((drawable)findviewbyid(r.drawable.cellborder)); 

this isn't working though, it's telling me can't cast view drawable. there way this?

you have use

getresources().getdrawable(r.drawable.cellborder); 

which return drawable.

if use findviewbyid() try find view in view hierarchy , return that. view not drawable, can't cast it.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -