Why button gets bigger when the background is set in android -


i encountered problem button view when set background using android:background attribute in xml. before set background, button has default size. when apply color background, getting bigger, though did not set different width or height on it.

this xml layout before set background attribute button

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical" android:layout_width="match_parent"     android:layout_height="match_parent">     <button         android:background="@color/white"         android:layout_gravity="center_horizontal"         android:id="@+id/btn_row_option_done"         android:text="done"         android:layout_width="wrap_content"         android:layout_height="wrap_content" />      <button         android:background="@color/white"         android:layout_gravity="center_horizontal"         android:text="edit"         android:id="@+id/btn_row_option_edit"         android:layout_width="wrap_content"         android:layout_height="wrap_content" />      <button         android:layout_gravity="center_horizontal"         android:text="delete"         android:id="@+id/btn_row_option_delete"         android:background="@color/red"         android:layout_width="wrap_content"         android:layout_height="wrap_content" />      <button         android:layout_gravity="center_horizontal"         android:text="cancel"         android:id="@+id/btn_row_option_cancel"         android:layout_width="wrap_content"         android:layout_height="wrap_content" /> </linearlayout> 

so cancel button default size in screenshot.

enter image description here

but when set color on cancel button this

 <button         android:background="@color/white"         android:layout_gravity="center_horizontal"         android:text="cancel"         android:id="@+id/btn_row_option_cancel"         android:layout_width="wrap_content"         android:layout_height="wrap_content" /> 

then button gets bigger default size, though did not make width or height bigger.

this screenshot

as can see above cancel button became bigger. setting background color. how can fix default size after set background color?

enter image description here

you have distinguish between size of button, width , height, whole area can click on, , image used displaying button.

the default button on android has padding applied drawable - seems smaller. has same size.

if make own drawable , apply no padding, background draw within whole bounds of view, making seem bigger.

you can use default button apply own color using appcompat. supports tinting background of default button.

<android.support.v7.widget.appcompatbutton     xmlns:app="http://schemas.android.com/apk/res-auto"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     app:backgroundtint="#ffaa00"/> <!-- <--- color here  --> 

...which let use same appearence.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -