android studio 圆角背景的使用

1.一般在drawable文件夹下新建文件translucent.xml

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

    <!-- 背景颜色 -->
    <solid android:color="#33CCFF" />

    <!-- 边框的宽度和颜色颜色 -->
    <stroke android:width="1dip" android:color="#33CCFF" />

    <!-- android:radius 弧形的半径 -->
    <corners android:radius="20dp"/>

    <!-- padding:Button里面的文字与Button边界的间隔 -->
    <padding
        android:left="10dp"
        android:top="10dp"
        android:right="10dp"
        android:bottom="10dp"
        />
    />
</shape>

2.使用translucent.xml

<Button
        android:id="@+id/button1"
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="10dp"
        android:text="按钮"
        android:background="@drawable/translucent"/>

使用之后,这个button按钮的背景就是弧形的样式了

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android Studio中,创建一个带圆角的对话框(通常用于弹出窗口或提示信息)可以通过自定义布局以及使用`android.R.attr.shape`属性来实现。以下是一个简单的步骤: 1. **创建布局**: 使用XML文件创建一个新的对话框布局(例如`rounded_popup_window.xml`),添加一个`FrameLayout`作为根,并设置其背景为半透明的`PopupWindow`背景: ```xml <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rounded_popup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@android:color/transparent" android:padding="16dp" android:elevation="16dp"> <View android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/rounded_background"/> <!-- Your content goes here, like TextView or other views --> </FrameLayout> ``` 在这个布局中,`rounded_background.xml`文件用来定义圆角背景: ```xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="16dp" /> <!-- 设置圆角大小 --> <solid android:color="#80000000" /> <!-- 半透明黑色背景 --> </shape> ``` 2. **创建PopupWindow**: 在Java或Kotlin代码中,你可以这样创建并显示带有圆角的`PopupWindow`: ```java // 假设你已经有了一个Button或者其他触发事件的控件 Button button = findViewById(R.id.my_button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 创建一个带圆角的PopupWindow实例 PopupWindow popup = new PopupWindow(RoundedPopupWindow.this, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); // 设置布局 popup.setContentView(R.layout.rounded_popup_window); // 设置弹出位置 popup.showAtLocation(button, Gravity.CENTER, 0, 0); // 其他配置,如动画、点击后消失等 } }); ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值