Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : Decreasing size of the Button

I am using Button in one of the layouts. I want Button size to be as small as the text/label size.

I am using the following code.

<Button  android:text="@string/cancle_button"  android:id="@+id/button1"  android:background="@drawable/back_button"  android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:textSize="12sp" android:textColor="#ffffff" android:textStyle="bold" /> 

But I want Button height to be same as text/label height. Whenever I decrease or increase the text height, Button height remains the same. How should I solve this problem?

like image 890
Swapnil Desai Avatar asked Oct 24 '13 04:10

Swapnil Desai


People also ask

How to decrease size of Button in android?

You can achieve this by setting android:minHeight="0dp" for the Button widget. And I guess this behavior is because there is some default value (may be a 48dp) set for Button widgets by the framework considering a minimum touch area.

How to decrease size of Button in android studio?

Solution 1: please use dimens. xml for specifying with and height for buttons. for tablet,please create folder values-sw600dp,values-sw720dp and put your dimens.

How can I make my Android button more attractive?

Using colors (background, text, border) Using custom shapes like circle, rounded corners and more. You can add images to your buttons to customize them. Using drawables to make gradients, dotted borders and more.


2 Answers

It's been almost a year since the question was asked. But I faced the problem now and got a solution. :) May be it will help someone.

You can achieve this by setting android:minHeight="0dp" for the Button widget.

And I guess this behavior is because there is some default value (may be a 48dp) set for Button widgets by the framework considering a minimum touch area.

like image 192
Sreekanth Avatar answered Sep 20 '22 05:09

Sreekanth


Use can take the image view in this case or if your taking text view in this case so you can take the image with proper size so that it would not bluer through these measures you can set small size for image Best way is you can take the image with that size you want to create its good way

like image 35
Gerald Horton Avatar answered Sep 20 '22 05:09

Gerald Horton