Android GUI issues in the tablet with changedButton.getBackground().setColorFilter(color, mode); -
how in title, app work in smartphones (samsung s2 , samsung s3), have gui bug in tablet (samsung galaxy tab s android 5.0.2).
this activity can changed user. can touch 1 button , change text , color this
but in tablet if user switch orientation or close , open activity, appear problem!
all buttons take color of first inputed color! , if user swap orientation or close , re-open activity returns normal state!
here code change buttons user has changed in past!
static string clickedbuttonviewid; private list<materievoti> materie; mysqlitehelper db = new mysqlitehelper(this); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_set_table); //get materie inside database list<materia> materia = db.getallmaterie(); //change textview inputed user if(materia.isempty()){ //do nothing }else { (materia mat : materia) { //change button values stored inside database int resid = getresources().getidentifier(mat.getid(), "id", getpackagename()); button changedbutton = (button) findviewbyid(resid); changedbutton.settext(mat.getmateria()); changedbutton.settypeface(null, typeface.bold); changedbutton.getbackground().setcolorfilter(mat.getcolor(), porterduff.mode.multiply); } } } //take data activityaddmateria protected void onactivityresult(int requestcode, int resultcode, intent data) { if(requestcode == 1) { if (resultcode == result_ok) { mysqlitehelper db = new mysqlitehelper(this); string result = data.getstringextra("result"); //take materia dialog int color = data.getintextra("color", 1); //take color dialog //controllo se il button è già presente nel db se presente aggiorno se non presente inserisco boolean modifica = db.exists(clickedbuttonviewid); if(!modifica) { //materia da inserire in un nuovo spazio db.addmateriatodb(new materia(clickedbuttonviewid, result, color)); }else{ //materia già presente nel button quindi aggiorno la materia db.updatemateria(new materia(clickedbuttonviewid, result, color)); toast.maketext(getapplicationcontext(), "materia modificata!", toast.length_long).show(); } //cambio subito il button int resid = getresources().getidentifier(clickedbuttonviewid, "id", getpackagename()); final button clickedtextview = (button) findviewbyid(resid); clickedtextview.settext(result); clickedtextview.getbackground().setcolorfilter(color, porterduff.mode.multiply); } if (resultcode == result_canceled) { //nessuna materia inserita } } }//onactivityresult drawable/buttons.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/button_pressed" android:state_pressed="true" /> <item android:drawable="@drawable/button_focused" android:state_focused="true" /> <item android:drawable="@drawable/button_default" /> </selector> drawable/button_default.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:radius="100dp" /> <solid android:color="#ffffff" /> <padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" /> <stroke android:width="3dp" android:color="#787878" /> </shape> i found problem don't know why doesn't work. if change changedbutton.getbackground().setcolorfilter(mat.getcolor(), porterduff.mode.multiply); changedbutton.setbackgroundcolor(mat.getcolor()); problem disappear lose button style property!
one way create drawable/button_style_red.xml, drawable/button_style_yellow.xml , code button.setdrawable(button_style_color); can change button. but there way change color not style of buttons??
the button.getbackground().setcolorfilter(mat.getcolor(), porterduff.mode.multiply); doesn't work device!!
this old question make changed button same style link


Comments
Post a Comment