java - How to add a background image to string? -
i'm making simple jokes app. i've used strings hold each , every joke. press joke in app, , gives me joke, press back, , press joke again , gives me joke #2 , on. problem jokes come white background. i've tried using android:background
in xml layout files still white background. think has fact i'm using strings display jokes. code i'm using jokes in .java
class :
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_starting_point); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } public void randomjoke (view view) { intent intent = new intent(this, displaymessageactivity.class); //random rand = new random(); //int lowerbound = 1, upperbound = 10; //int randomnumber = rand.nextint(upperbound - lowerbound + 1) + lowerbound; //string jokenumber = "joke" + string.valueof(randomnumber); //string mess = getresources().getstring(getstringresourcepath(getapplicationcontext(),jokenumber)); string jokenumber = "joke" + string.valueof(iteration); iteration += 1; string mess = getresources().getstring(getstringresourcepath(getapplicationcontext(), jokenumber)); intent.putextra(extra_message, mess); startactivity(intent); } public int getstringresourcepath(context context, string name) { int joke = context.getresources().getidentifier(name, "string", "com.primarycode.punnyjokes"); return joke; } }
i assume, might using textview
show joke in displaymessageactivity
. can achieve follows:
in xml layout:
android:background="@drawable/myresouce"
or pragmatically in oncreate()
follows:
textview.setbackgroundresource(r.drawable.myresouce);
if want use color, use follows in layout xml:
android:background="#eee"
Comments
Post a Comment