Is there a way to programmatically set src image for ToggleButton?

I am using a ToggleButton with an image. The image is 16x16, however, I want the button to be 50x50 so that when users click around the image even then the action is taken. This is how I'm avoiding the fat finger problem.

This is how my ToggleButton is in the XML

<ToggleButton android:id="@+id/fav" android:layout_width="50dp" android:layout_height="50dp" android:background="#FFFFFF" android:gravity="center" android:focusable="false" android:layout_marginRight="10dp" android:padding="15dp" />

and I set the background programmatically like this:

if (holder.favButton.isChecked()) holder.favButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.star_2)); else holder.favButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.star_1));


The image looks expanded and blurry because the width and height is 50dp, however, the image is only 16x16. Instead of setting the background with setBackgroundDrawable, I want to find a way to set the image src of the button. Because if I'm setting the background then the image takes over the entire background which is 50x50.


Can this help you? State List I alway using a custom drawable with Selector and set it to ToggleButton


  • ionic 3, lazy-loading tabs components
  • jQuery script works only once
  • Deserialize JSON from API response
  • Sharing Violation on image View and Edit WPF
  • Image Map-like Blackberry Control - CLDC Application
  • Stored data can't access in Yii
  • onMeasure() called with EXACTLY and spec size 0
  • How to notify parent's view model when child's view model property is changed?
  • I can't show LinearLayout at bottom to scroll view
  • Can I override some attribute of drawable shape?
  • Sticky Footer Below ListView in Android Layout
  • Android custom dialog linearlayout size same as dialogs bg image
  • Background image crashes android
  • How to automatically pop-up keyboard?
  • Float Label hint (TextInputLayout) not works with Android Data Binding
  • Android Custom dialog inflating from layout - alignment issue
  • EditText ignores the ImeActionLabel
  • Toolbar shifts up, when soft keyboard appears
  • Gray line inside cardview :)?
  • How Lists (specifically, RecyclerView with CardViews) in Android work
  • Google Custom Search with transparent background
  • Disable Enter in editText android
  • Android fill_parent issue
  • Cannot resolve symbol 'MyApi'
  • If I include Java 8 in my Android app does that affect which devices it will work on?
  • Repeat a vertical line on every page in Report Builder / SSRS
  • DotNetZip - Calculate final zip size before calling Save(stream)
  • Possible to stop flickering java tooltip in heavyweight mode?
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • How to model a transition system with SPIN
  • Release, debug version and Authorization Google?
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Cant find why the layout is getting smaller
  • How to stop GridView from loading again when I press back button?
  • Bitwise OR returns boolean when one of operands is nil
  • sending mail using smtp is too slow
  • costura.fody for a dll that references another dll
  • Binding checkboxes to object values in AngularJs