java - Android app dynamically added button is different colour to layout buttons -


i'm trying add new button dialogfragment, , button appearing, font , colour different other buttons.

the other buttons generated layoutinflater on layout in xml file. buttons in xml file like:

<relativelayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent">      ... other parts of layout...      <linearlayout     android:id="@+id/ll_buttons"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_aligntop="@id/rg1"     android:layout_torightof="@id/rg1"     android:layout_toendof="@id/rg1"     android:layout_marginleft="30dp"     android:layout_marginstart="30dp"     android:orientation="vertical"     >     <button         android:id="@+id/ok_button"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:text="@string/fragment_add_custom_target_ok"           />      <button         android:id="@+id/cancel_button"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:text="@string/fragment_add_custom_target_cancel"         /> </linearlayout>  </relativelayout> 

i (in circumstances), adding delete button follows:

    public class customtargetpickerfragment extends dialogfragment { @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {         view v = inflater.inflate(r.layout.fragment_add_custom_target, container, false);         dialog dialog=getdialog();         dialog.settitle(getstring(r.string.custom_target_picker_title));          // , process arguments         bundle bundle = getarguments();         if (bundle.getboolean(tag_has_delete)) {             // add delete button             // todo: not rendering              linearlayout layout = (linearlayout) v.findviewbyid(r.id.ll_buttons);             button deletebutton = new button(getactivity());             deletebutton.settext(getstring(r.string.custom_target_picker_delete_label));              deletebutton.setlayoutparams(new linearlayout.layoutparams(linearlayout.layoutparams.match_parent, linearlayout.layoutparams.wrap_content));             deletebutton.setonclicklistener(deletebuttonlistener);             layout.addview(deletebutton);         } 

what should doing make new button same ones created layout? many thanks

you add deletebutton in layout xml with

android:visibility="gone" 

then in class

if (bundle.getboolean(tag_has_delete)) {         // show delete button          button deletebutton = (button)v.findviewbyid(r.id.delete_button);         deletebutton.setvisibility(view.visible);         deletebutton.setonclicklistener(deletebuttonlistener);     } 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -