Android實(shí)現(xiàn)圓角彈框功能
自定義彈窗類——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);//點(diǎn)擊其他區(qū)域時(shí) true 關(guān)閉彈窗 false 不關(guān)閉彈窗 tvmydailog01 = findViewById(R.id.tv_mydailog01); tvmydailog02 = findViewById(R.id.tv_mydailog02); ivdailog = findViewById(R.id.iv_mydailog); } /*設(shè)置圖片接口*/ public void setImageResource(int resId){ ivdailog.setImageResource(resId); } /*設(shè)置文字接口*/ public void setText01(String str){ tvmydailog01.setText(str); } public void setText02(String str){ tvmydailog02.setText(str); } /*設(shè)置文字顏色接口*/ 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);//加載布局 //設(shè)置透明背景 Window window = getWindow(); window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); }}
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='http://www.cgvv.com.cn/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>
調(diào)用
MySetDailog mySetDailog = new MySetDailog(BindActivity.this);mySetDailog.show();
到此這篇關(guān)于Android實(shí)現(xiàn)圓角彈框功能的文章就介紹到這了,更多相關(guān)android圓角彈框內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Gitlab CI-CD自動(dòng)化部署SpringBoot項(xiàng)目的方法步驟2. 基于javascript處理二進(jìn)制圖片流過(guò)程詳解3. ajax請(qǐng)求添加自定義header參數(shù)代碼4. Java Lock接口實(shí)現(xiàn)原理及實(shí)例解析5. 詳談ajax返回?cái)?shù)據(jù)成功 卻進(jìn)入error的方法6. axios和ajax的區(qū)別點(diǎn)總結(jié)7. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)8. 淺談SpringMVC jsp前臺(tái)獲取參數(shù)的方式 EL表達(dá)式9. ASP中解決“對(duì)象關(guān)閉時(shí),不允許操作。”的詭異問(wèn)題……10. 利用CSS3新特性創(chuàng)建透明邊框三角
