当我没有设置任何东西时按钮的边框

border of button when I didnt set anything

我是 android 开发的初学者,所以这个问题可能很蹩脚。当我创建按钮时,它有一些可见的边框,即使我没有设置任何边框并且背景只是颜色。更多示例:

<RelativeLayout
    android:id="@+id/buttonLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorButtonBlue"
    android:gravity="bottom"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent">

    <Button
        android:id="@+id/loginButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_centerInParent="true"
        android:background="@color/colorButtonBlue"
        android:fadingEdge="none"
        android:padding="10dp"
        android:text="@string/action_sign_in"
        android:textAllCaps="false"
        android:textColor="@color/white"
        android:textSize="@dimen/big_size" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/loginButton"
        android:layout_centerVertical="true"
        android:src="@drawable/arrow_icon"
        />


</RelativeLayout>

这是它的样子(我希望它是可见的,在移动设备上比在模拟器上更明显)

我知道我可以创建自己的样式并抑制它,但我仍然想了解为什么会这样。提前致谢

尝试为按钮

添加这个属性
android:stateListAnimator="@null"

出现边框是因为按钮的默认背景

也设置按钮背景null会解决这个问题。

<RelativeLayout
    android:id="@+id/buttonLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorButtonBlue"
    android:gravity="bottom"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent">

    <Button
        android:id="@+id/loginButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_centerInParent="true"
        android:background="@null"
        android:fadingEdge="none"
        android:padding="10dp"
        android:text="@string/action_sign_in"
        android:textAllCaps="false"
        android:textColor="@color/white"
        android:textSize="@dimen/big_size" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/loginButton"
        android:layout_centerVertical="true"
        android:src="@drawable/arrow_icon"
        />
</RelativeLayout>

我不确定,我现在也不能签到,但我认为你应该试试 android:elevation。您可能应该将高度更改为 0,因为我认为默认值不是。希望对您有所帮助!