Android : Decreasing size of the Button

Swapnil Desai picture Swapnil Desai · Oct 24, 2013 · Viewed 28.5k times · Source

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?

Answer

Sreekanth picture Sreekanth · Oct 18, 2014

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.