Android-自定义按钮颜色导致不必要的大小调整

Android-自定义按钮颜色导致不必要的大小调整,android,xml,textview,android-ui,android-button,Android,Xml,Textview,Android Ui,Android Button,显然改变了这一点: <Button android:id="@+id/login" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_above="@+id/register" android:background="@color/bluegreen" android:text="Log In" android:

显然改变了这一点:

<Button
    android:id="@+id/login"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/register"
    android:background="@color/bluegreen"
    android:text="Log In"
    android:textColor="@android:color/white" />

为此:

<Button
    android:id="@+id/login"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/register"

    android:text="Log In"
    android:textColor="@android:color/white" />

结果导致登录按钮缩小(并且添加上面缺少的行会导致更改恢复,因此我确信它与行android:background=“@color/bluegreen”)相关:

示例图像:

strings.xml

omv
设置
你好,世界!
用户名
密码
#292929
#43BFC7

如果您想增加按钮的大小,请考虑为您的
android:layout\u height使用不同的值。下面是一个示例:

<Button
    android:id="@+id/login"
    android:layout_width="fill_parent"
    android:layout_height="100dp"
    android:layout_above="@+id/register"
    android:background="@color/bluegreen"
    android:text="Log In"
    android:textColor="@android:color/white" />

您可以利用该值将其放到您想要的位置

希望这有帮助。祝你好运

编辑


您的按钮与默认按钮的外观不同的原因是默认按钮使用了一种特殊的图像类型,该图像类型将填充构建到图像中。此特殊图像称为a,通常用于防止您面临的问题。ADT提供了将
png
转换为
9patch
的工具。标准颜色不会更改为
9patch
,因此内容显示如上所示。

@MarcinOrlowski需要详细说明吗?我希望它像下面的按钮一样填充家长。。。这可能吗?我只是想防止它在改变颜色时收缩-不是固定大小。我可以去掉填充物吗?即使我将两个按钮都设置为android:layout_height=“40dp”,它也会在按钮的左右两侧留下填充,这会使它看起来比另一个按钮小。我只需要两个按钮看起来完全相同,并且添加android:layout\u height=“40dp”这两个按钮仍然会给我们留下不需要的填充。@user3009687默认使用背景颜色时不使用填充。您在左侧和右侧看到的是使用
fill\u parent
作为
android:layout\u width
的值的效果。它拉伸按钮以填充父视图(在本例中是屏幕的整个宽度)。请向我们显示完整代码,然后我可以在IDE中运行它。
<Button
    android:id="@+id/login"
    android:layout_width="fill_parent"
    android:layout_height="100dp"
    android:layout_above="@+id/register"
    android:background="@color/bluegreen"
    android:text="Log In"
    android:textColor="@android:color/white" />