How to set programmatically android:background="@drawable/button_bg"?

GunbitGunbit DEMember ✭✭
edited May 2016 in Xamarin.Android

It is possibly to set the Background form imageButton to a resource file?

I need this to change the layout form the Button if is selected and unselected.

ImageButton imageBtn = new ImageButton (this); imageBtn.SetMinimumWidth(281); imageBtn.SetMinimumHeight(51); if (l.local == "DE") { imageBtn.SetImageResource (Resource.Drawable.dt); } else { imageBtn.SetImageResource (Resource.Drawable.en); } imageBtn.Click += (sender, e) => { imageBtn.Selected = true; }; row.AddView(imageBtn);

Thanks for Help

Best Answer

Answers

  • SHIVANKUCHAUHANSHIVANKUCHAUHAN USMember ✭✭✭

    Add a file in drawable folder say mybutton.xml

    <?xml version="1.0" encoding="utf-8" ?>



    add color in values folder :smile:
    #FFFFFF
    #AAFFFF:smile:

    refer to view and set background resource as

    View view = inflater.Inflate(Resource.Layout.ABCView, container, false);
    view.FindViewById(Resource.Id.btnAbc).SetBackgroundResource(Resource.Drawable.mybutton);

  • SHIVANKUCHAUHANSHIVANKUCHAUHAN USMember ✭✭✭
    edited May 2016

    Add a file in drawable folder say mybutton.xml

    <?xml version="1.0" encoding="utf-8"?>




    refer to view and set background resource as

    View view = inflater.Inflate(Resource.Layout.ABCView, container, false);
    view.FindViewById(Resource.Id.btnAbc).SetBackgroundResource(Resource.Drawable.mybutton);

    folow http://www.mkyong.com/android/android-imagebutton-selector-example/

Sign In or Register to comment.