Genadinik Genadinik - 1 month ago 13
Android Question

Android - button background color shrinks the height of the button

I have this button

<Button
android:id="@+id/learn"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop ="5dp"
android:text="Hello StackOverflow"
style="@style/home_page_buttons"
/>


and I am trying to give it this style

<style name="home_page_buttons">
<item name="android:layout_marginLeft">15dp</item>
<item name="android:layout_marginRight">15dp</item>

<item name="android:textColor">@color/light_best_blue</item>
<item name="android:textStyle">bold</item>
<item name="android:color">@color/white</item>
<item name="android:background">@color/white</item>

</style>


This line:

<item name="android:background">@color/white</item>


makes the backgrond white as I wanted, but for some reason, it shrinks down the height of the button and makes it ugly.

Any idea why that happens and how to stop this side effect?

Thanks!

Answer

ABDOU is right, this could be a solution for you

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="rectangle">
    <gradient android:startColor="#FFFFFF" android:endColor="#BBBBBB" 
            android:angle="270"/>
    <stroke android:width="2dp"
            android:color="#555555" />
    <corners android:bottomRightRadius="7dp"
        android:bottomLeftRadius="5dp" 
        android:topLeftRadius="5dp"
        android:topRightRadius="7dp"/>    
</shape>

Create this as XML in drawable, and set this to your BackgoundColor

Comments