您的位置:首页技术文章
文章详情页

Android实现圆角弹框功能

浏览:21日期:2022-09-21 17:40:06

自定义弹窗类——Android 透明圆角弹窗

import android.content.Context;import android.graphics.Color;import android.graphics.drawable.ColorDrawable;import android.os.Bundle;import android.view.Window;import android.widget.ImageView;import android.widget.TextView;import androidx.annotation.NonNull;import androidx.appcompat.app.AlertDialog;public class MySetDailog extends AlertDialog { TextView tvmydailog01; TextView tvmydailog02; ImageView ivdailog; public MySetDailog(@NonNull Context context ) { super(context); setCanceledOnTouchOutside(true);//点击其他区域时 true 关闭弹窗 false 不关闭弹窗 tvmydailog01 = findViewById(R.id.tv_mydailog01); tvmydailog02 = findViewById(R.id.tv_mydailog02); ivdailog = findViewById(R.id.iv_mydailog); } /*设置图片接口*/ public void setImageResource(int resId){ ivdailog.setImageResource(resId); } /*设置文字接口*/ public void setText01(String str){ tvmydailog01.setText(str); } public void setText02(String str){ tvmydailog02.setText(str); } /*设置文字颜色接口*/ public void setColor01(int color01){ tvmydailog01.setTextColor(color01); } public void setColor02(int color02){ tvmydailog02.setTextColor(color02); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dialog_mydailog);//加载布局 //设置透明背景 Window window = getWindow(); window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); }}

Android实现圆角弹框功能

xml布局文件

<?xml version='1.0' encoding='utf-8'?><LinearLayout xmlns:android='http://schemas.android.com/apk/res/android' android: android:layout_width='325dp' android:layout_height='162dp' android:paddingTop='15dp' android:orientation='vertical' android:layout_gravity='center_horizontal' android:gravity='center' android:background='@drawable/bg_round_dailog'> <ImageView android: android:layout_width='wrap_content' android:layout_height='66dp' android:src='https://www.haobala.com/bcjs/@drawable/icon_warning' /> <TextView android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:layout_marginTop='@dimen/dp_12' android:maxLines='1' android:text='@string/str_upload_fail' android:textColor='#BB340F' android:textStyle='bold' android:textSize='18sp' /> <TextView android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:text='@string/str_push_true_phone' android:textColor='#ff555555' android:textSize='15sp' /></LinearLayout>

调用

MySetDailog mySetDailog = new MySetDailog(BindActivity.this);mySetDailog.show();

到此这篇关于Android实现圆角弹框功能的文章就介绍到这了,更多相关android圆角弹框内容请搜索好吧啦网以前的文章或继续浏览下面的相关文章希望大家以后多多支持好吧啦网!

标签: Android
相关文章: