android - 是否可以在android按钮中指定边框?

标签 android button

是否可以在 main.xml 中指定 Android 按钮的边框? [附注 没有“包含笔划标记的单独 xml 文件”,但在我定义按钮的原始文件中 没有“通过编程动态”解决方案 和“图像”解决方案]

  <Button
    android:background="#FFFFFF"
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    android:text="Player 3"
    android:layout_x="0px"
    android:layout_y="0px"
    android:id="@+id/p3"
    android:layout_weight="1" 

/>  

这里我正在动态更改背景,但问题是,对于 2 个按钮,没有边框。

最佳答案

尝试使用形状

我的形状.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <corners
        android:bottomLeftRadius="7dp"
        android:bottomRightRadius="7dp"
        android:radius="0.1dp"
        android:topLeftRadius="7dp"
        android:topRightRadius="7dp" />

    <solid android:color="#FFFFFF" />

    <stroke
        android:width="1dp"
        android:color="#E8E6E7" />

</shape>

和按钮

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/my_shape"
    android:text="Button" />

截图

enter image description here

希望对您有所帮助。

关于android - 是否可以在android按钮中指定边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17564884/

相关文章:

android - 如何在 Activity fragment 上运行测试

java - Android 文档列表 查看 XML 格式的示例源代码

android - Google Play 上所有 Android 应用程序的列表

java - FirebaseRecyclerAdapter 但未能将 java.util.HashMap 类型的值转换为字符串?

android - 如何在不使用 id 的情况下操作按钮的内容;安卓?

android - 在 Jetpack compose 中绘制动画圆

点击 UIButton 时手指的 iOS x 坐标

css - 带尖边和阴影的按钮

c++ - 如何实现一个在点击时执行不同功能的通用按钮类?

c# - 比较 Winform 按钮颜色