Custom Button Always Too Big
I am trying to create a custom button with its shape being as similar as possible to the one of the Android default button. The problem is, no matter how much I reduce the height,
Solution 1:
when you set any Background to A Button its hight will increase check below test cases
- when you set both button background the button size are same
Try this you also need to set android:background to your default button like this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:background="@drawable/demo"
android:text="custom"
/>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:background="@color/colorAccent"
android:text="default"
/>
</LinearLayout>
OUTPUT
without setting custom background to your custom button
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:text="custom"
/>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:background="@color/colorAccent"
android:text="default"
/>
</LinearLayout>
Output
EDIT Android Button has default padding.
check the default Size of button
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:background="@drawable/demo"
android:text="custom"
/>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:text="default"
/>
</LinearLayout>
Solution 2:
Android Button has default padding.
When I set android:background="@android:color/holo_blue_bright"
in the Button.
It will be the same of custom Button
.
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:text="default"
android:background="@android:color/holo_blue_bright"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/button"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.501" />
Output
Post a Comment for "Custom Button Always Too Big"