Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Android button with image and text programatically?

$
0
0

How can I achieve this:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_text"
    android:drawableLeft="@drawable/button_icon"
    ... />

via code?

So far, I've got this:

btn = new Button(this);            
            btn.Text = "Maps";
            btn.Click += StartSpotify;
            btn.Gravity = GravityFlags.Left | GravityFlags.CenterVertical;
            btn.TextSize = 30;
            btn.SetPadding(60, 0, 0, 0);
            btn.LayoutParameters = loParams;
            btn.SetBackgroundColor(Android.Graphics.Color.Transparent);
            col1row2.AddView(btn);

which creates the button correctly, but I need to add an image to the left of the text on the button.

Easily achievable via axml, but I cannot figure it out via code nor can I find any help on the API or samples?


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>