android - 如何在 Android 中使带有可见边框的按钮背景透明?

标签 android android-view

这是按钮的编码。我只想让边框可见,按钮的背景应该是不可见的。但是有了这段代码,一切都变得不可见了。

<Button
    android:id="@+id/button3"
    android:layout_width="200dp"
    android:layout_height="60dp"
    android:text="Sign In"
    android:textAllCaps="false"
    android:layout_gravity="center"
    android:layout_marginTop="50dp"
    android:textColor="@color/white"
   android:background="@android:color/transparent"

enter image description here

我希望我的按钮看起来像这样。

最佳答案

 <Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:background="@drawable/button_bg"/>

按钮_bg.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
  <corners
      android:radius="2dp" />
  <stroke
      android:width="2px"
      android:color="@color/your_border_color" />
</shape>

关于android - 如何在 Android 中使带有可见边框的按钮背景透明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44900496/

相关文章:

安卓绘图填充工具

android - getWindow().setBackgroundDrawable 和 getWindow().getDecorView().setBackgroundDrawable 之间的区别

android - 使 View 的大小完全适合我在其中绘制的路径

android - 使按钮的背景颜色发生变化并在单击后保持不变

android - 使用 Flutter 从方法中获取一些变量值

安卓 WebView : Does loading from resources still require Internet permissions?

android - PendingIntent 不适用于 FCM 通知

android - 寻找某种方法来监视错误并在Unity上崩溃

Android 应用程序 - 在环聊拨号器中接听电话

android-animation - 使用 Object AnimatorAndorid 进行对角线平移