Skip to content Skip to sidebar Skip to footer

Make Android Imagebutton Look Like Button

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:

<stylename="Widget.MaterialComponents.Button"parent="Widget.AppCompat.Button"><itemname="enforceMaterialTheme">true</item><itemname="android:background">@empty</item><itemname="enforceTextAppearance">true</item><itemname="android:textAppearance">?attr/textAppearanceButton</item><itemname="android:textColor">@color/mtrl_btn_text_color_selector</item><itemname="android:paddingLeft">@dimen/mtrl_btn_padding_left</item><itemname="android:paddingRight">@dimen/mtrl_btn_padding_right</item><itemname="android:paddingTop">@dimen/mtrl_btn_padding_top</item><itemname="android:paddingBottom">@dimen/mtrl_btn_padding_bottom</item><itemname="android:insetLeft">0dp</item><itemname="android:insetRight">0dp</item><itemname="android:insetTop">@dimen/mtrl_btn_inset</item><itemname="android:insetBottom">@dimen/mtrl_btn_inset</item><itemname="android:stateListAnimator"ns2:ignore="NewApi">@animator/mtrl_btn_state_list_anim</item><itemname="cornerRadius">@null</item><itemname="elevation">@dimen/mtrl_btn_elevation</item><itemname="iconPadding">@dimen/mtrl_btn_icon_padding</item><itemname="iconTint">@color/mtrl_btn_text_color_selector</item><itemname="rippleColor">@color/mtrl_btn_ripple_color</item><itemname="backgroundTint">@color/mtrl_btn_bg_color_selector</item><itemname="shapeAppearance">?attr/shapeAppearanceSmallComponent</item></style>

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"