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
Post a Comment