The documentation for ImageButton says: By default, an ImageButton looks like a regular Button This is obviously wrong because when I put both into a layout:
Solution 1:
Are you using material design? Your Button does not look like the regular button that default style is @style/Widget.AppCompat.Button
, but like the material button, which default style is @style/Widget.MaterialComponents.Button
. If you set the style of the Button to @style/Widget.AppCompat.Button
, you will see it looks the same as the ImageButton with default style @style/Widget.AppCompat.ImageButton
This is @style/Widget.AppCompat.Button
, you can see that it has been expanded on the basis of @style/Widget.AppCompat.Button
:
<style name ="Widget.MaterialComponents.Button" parent ="Widget.AppCompat.Button" > <item name ="enforceMaterialTheme" > true</item > <item name ="android:background" > @empty</item > <item name ="enforceTextAppearance" > true</item > <item name ="android:textAppearance" > ?attr/textAppearanceButton</item > <item name ="android:textColor" > @color/mtrl_btn_text_color_selector</item > <item name ="android:paddingLeft" > @dimen/mtrl_btn_padding_left</item > <item name ="android:paddingRight" > @dimen/mtrl_btn_padding_right</item > <item name ="android:paddingTop" > @dimen/mtrl_btn_padding_top</item > <item name ="android:paddingBottom" > @dimen/mtrl_btn_padding_bottom</item > <item name ="android:insetLeft" > 0dp</item > <item name ="android:insetRight" > 0dp</item > <item name ="android:insetTop" > @dimen/mtrl_btn_inset</item > <item name ="android:insetBottom" > @dimen/mtrl_btn_inset</item > <item name ="android:stateListAnimator" ns2:ignore ="NewApi" > @animator/mtrl_btn_state_list_anim</item > <item name ="cornerRadius" > @null</item > <item name ="elevation" > @dimen/mtrl_btn_elevation</item > <item name ="iconPadding" > @dimen/mtrl_btn_icon_padding</item > <item name ="iconTint" > @color/mtrl_btn_text_color_selector</item > <item name ="rippleColor" > @color/mtrl_btn_ripple_color</item > <item name ="backgroundTint" > @color/mtrl_btn_bg_color_selector</item > <item name ="shapeAppearance" > ?attr/shapeAppearanceSmallComponent</item > </style >
Copy So, you can customize a new style for ImageButton, and then add those new style attributes of material button to the custom style (mainly cornerRadius
, elevation
, and rippleColor
)
or set the button's style to @style/Widget.AppCompat.Button
, while will also make the ImageButton looks like the Button :P
Post a Comment for "Make Android Imagebutton Look Like Button"