有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java按钮边框不显示

我尝试在安卓中为按钮添加边框,但不幸的是,我看不到按钮边框

可拉伸锉刀👇

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:安卓="http://schemas.安卓.com/apk/res/安卓">
    <item>
        <shape 安卓:shape="rectangle">
            <corners 安卓:radius="12dp" />
            <stroke 安卓:width="3px" 安卓:color="#7E8082" />
        </shape>
    </item>
</selector>

XML👇

<Button
        安卓:id="@+id/btn_signup"
        安卓:layout_width="match_parent"
        安卓:layout_height="60dp"
        安卓:layout_marginTop="122dp"
        安卓:background="@drawable/bg_signup"
        安卓:fontFamily="@font/poppins_semibold"
        安卓:text="Create an Account"
        安卓:textAllCaps="false"
        安卓:textColor="@color/black"
        app:layout_constraintTop_toBottomOf="@+id/btn_login" />

I want this button


共 (3) 个答案

  1. # 1 楼答案

    使用Style属性而不是android:background="@drawable/bg_signup"

    制作一个自定义样式,然后将其命名为android:style="@style/bg_signup"

  2. # 2 楼答案

    您不需要使用定制的绘图工具,只需使用MaterialButton

           <com.google.android.material.button.MaterialButton
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               style="@style/Widget.MaterialComponents.Button.OutlinedButton"
               app:strokeColor="#7E8082"
               app:strokeWidth="1dp"
               app:cornerRadius="12dp"/>
    

    enter image description here

  3. # 3 楼答案

    不要对单个选项使用选择器直接使用shape

    bg_注册

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="#cdcdcd"/>
        <corners
            android:radius="4dp"
        />
        <stroke
            android:width="1dp"
            android:color="#000"
        />
    </shape>