Padding not working on ImageButton
You have to add to Your ImageButton definition android:scaleType=”fitCenter” or other scaleType like fitXY, because by default image try to scale as much as possible and ignore padding
You have to add to Your ImageButton definition android:scaleType=”fitCenter” or other scaleType like fitXY, because by default image try to scale as much as possible and ignore padding
You can change the tint, quite easily in code via: ImageButton button = (ImageButton) this.findViewById(R.id.button_i_want_to_modify); button.setColorFilter(Color.argb(255, 255, 255, 255)); // White Tint
your code is trying to change the background of the button. not its image. Those are two different things ((ImageButton) view).setImageResource(R.drawable.icon2);
This probably only covers part of the differences, it would be helpful to actually look at the Android Source tree to see exactly what’s going on. ImageButtons has push states, where as a clickable image does not. You also can’t call setText for ImageButton, you can with a regular button. They all derive from view, … Read more
You can use android:background=”@null” for your ImageButton. See also: Android Developers official guide on Buttons
This is the simple only you have to set background color as transparent ImageButton btn=(ImageButton)findViewById(R.id.ImageButton01); btn.setBackgroundColor(Color.TRANSPARENT);
This works for me: <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <!– NOTE: order is important (the first matching state(s) is what is rendered) –> <item android:state_selected=”true” android:drawable=”@drawable/info_icon_solid_with_shadow” /> <item android:drawable=”@drawable/info_icon_outline_with_shadow” /> </selector> And then in java: //assign the image in code (or you can do this in your layout xml with the src attribute) imageButton.setImageDrawable(getBaseContext().getResources().getDrawable(R.drawable….)); //set … Read more
For even better result: <ImageButton android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:src=”https://stackoverflow.com/questions/30959610/@android:drawable/ic_button” android:background=”?attr/selectableItemBackgroundBorderless” />
As you can’t use android:text I recommend you to use a normal button and use one of the compound drawables. For instance: <Button android:id=”@+id/buttonok” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:drawableLeft=”https://stackoverflow.com/questions/4457030/@drawable/buttonok” android:text=”OK”/> You can put the drawable wherever you want by using: drawableTop, drawableBottom, drawableLeft or drawableRight. UPDATE For a button this too works pretty fine. Putting android:background is … Read more
There’s no differences, except default style. ImageButton has a non-null background by default. EDIT: Also, ImageButton.onSetAlpha() method always returns false, scaleType is set to center and it’s always inflated as focusable. Here’s ImageButton‘s default style: <style name=”Widget.ImageButton”> <item name=”android:focusable”>true</item> <item name=”android:clickable”>true</item> <item name=”android:scaleType”>center</item> <item name=”android:background”>@android:drawable/btn_default</item> </style>