java - 当我自定义高度和自定义背景时,为什么按钮文本不是 wrap_content 并且消失了?
问题描述
当我自定义高度和自定义背景时,为什么按钮文本不是 wrap_content 并且消失了?
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" />
解决方案
你的问题是身高。利用:
android:layout_height="wrap_content"
在任何情况下,您都不需要自定义背景来获得圆角。
只需使用:
<com.google.android.material.button.MaterialButton
....
style="@style/Widget.MaterialComponents.Button"
app:cornerRadius=".."
.../>
推荐阅读
- php - 如何修复 php 和 stripe 中的 403 POST 错误
- tailwind-css - tailwindcss 扩展托盘以使用青色
- c++ - 为什么 C++ 中没有非同步智能指针?
- java - Spring Boot 中的 Liquibase 更改日志
- python - 由于 AttributeError,应用程序构建在 Pyinstaller 版本 4.3 但不是 4.4 成功:模块'PyQt5'没有属性'__version__'
- amazon-web-services - 当年份在 aws 胶水上的 pyspark 中有两位数时,如何将字符串转换为日期
- linux - linux(或任何操作系统)文件系统如何“准确地”处理并发文件 I/O(内核调度)?
- javascript - 在 laravel 中搜索自动完成 ajax
- c - C 宏:提取/转储所有评估的编译时间#defines
- java - 休眠关系序列不存在