【发布时间】:2018-09-03 15:19:03
【问题描述】:
我为我的按钮制作了自定义样式。它完美地出现在 Layout Preview 中(通过 Android Studio XML Preview),但是当我运行应用程序时,按钮没有想要的边框。
知道可能导致这种情况的原因吗?
activity_main.xml
<style name="Button.Pink" parent="Button">
<item name="android:background">@drawable/rounded_corners_button</item>
<item name="android:backgroundTint">@color/pink</item>
<item name="android:textColor">@color/white</item>
</style>
styles.xml
<Button
style="@style/Button.Pink"
android:id="@+id/btn_sale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|start"
android:enabled="false"
android:foreground="?attr/selectableItemBackground"
android:text="@string/sale"
android:layout_marginTop="4dp"
android:layout_marginStart="4dp"
android:visibility="gone"
tools:visibility="visible" />
rounded_corners_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="65dp" />
</shape>
</item>
</selector>
编辑: 添加一些渲染器的图片
【问题讨论】:
-
您正在检查哪个版本的 api?
-
分钟 21,目标 api 28
标签: android android-layout android-xml