简体   繁体   English

当我自定义高度和自定义背景时,为什么按钮文本不是 wrap_content 并且消失了?

[英]Why the button text it's not wrap_content and gone when I custom Hight and custom background?

Why the button text it's not wrap_content and gone when I custom Hight and custom background?当我自定义高度和自定义背景时,为什么按钮文本不是 wrap_content 并且消失了?

XML Code: XML 代码:

<Button
            android:id="@+id/button_create"
            android:layout_width="wrap_content"
            android:layout_height="35dp"
            android:layout_marginEnd="8dp"
            android:background="@drawable/bg_button_3"
            android:text="@string/create"
            android:theme="@style/FontTheme1"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

在此处输入图像描述

Your issue is the height.你的问题是身高。 Use:利用:

android:layout_height="wrap_content"

In any case you don't need a custom background to have rounded corners.在任何情况下,您都不需要自定义背景来获得圆角。
Just use:只需使用:

<com.google.android.material.button.MaterialButton
   ....
   style="@style/Widget.MaterialComponents.Button"
   app:cornerRadius=".."
    .../>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM