Android自定義彈窗提示效果
本文實(shí)例為大家分享了Android 自定義彈窗提示的具體代碼,供大家參考,具體內(nèi)容如下
Java文件:
private void showSetDeBugDialog() { AlertDialog.Builder setDeBugDialog = new AlertDialog.Builder(this); //獲取界面 View dialogView = LayoutInflater.from(this).inflate(R.layout.system_admin_psw_alert_dialog, null); //將界面填充到AlertDiaLog容器并去除邊框 setDeBugDialog.setView(dialogView,0,0,0,0); //初始化控件 TextView but_cancel = dialogView.findViewById(R.id.but_cancel); TextView but_confirm = dialogView.findViewById(R.id.but_confirm); //取消點(diǎn)擊外部消失彈窗 setDeBugDialog.setCancelable(false); //創(chuàng)建AlertDiaLog setDeBugDialog.create(); //AlertDiaLog顯示 final AlertDialog customAlert = setDeBugDialog.show(); //設(shè)置AlertDiaLog寬高屬性 // WindowManager.LayoutParams params = Objects.requireNonNull(customAlert.getWindow()).getAttributes(); // params.width = 200; // params.height = 200 ; // customAlert.getWindow().setAttributes(params); // 移除dialog的decorview背景色 Objects.requireNonNull(customAlert.getWindow()).getDecorView().setBackground(null); //設(shè)置自定義界面的點(diǎn)擊事件邏輯 but_cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { customAlert.dismiss(); } }); but_confirm.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { customAlert.dismiss(); } }); }
布局文件:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="@drawable/fillet_fill_stroke"> <ImageView android:layout_width= "38dp" android:layout_height="38dp" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" android:src="@mipmap/wenti"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:paddingTop="20dp" android:paddingBottom="20dp" android:textColor="#5C5C5C" android:textSize="20sp" android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:text="確定要退出嗎?"/> <LinearLayout android:layout_width="match_parent" android:layout_height="1dp" android:background="#eee"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/but_cancel" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:textColor="#999" android:paddingTop="15dp" android:paddingBottom="15dp" android:text="取消"/> <LinearLayout android:layout_width="1dp" android:layout_height="match_parent" android:background="#eee"/> <TextView android:id="@+id/but_confirm" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:paddingTop="15dp" android:paddingBottom="15dp" android:textColor="#5C5C5C" android:textStyle="bold" android:text="確定"/> </LinearLayout> </LinearLayout>
資源文件:
背景樣式
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <!--描邊設(shè)置--> <stroke android:color="@android:color/darker_gray" android:width="1px" /> <!--填充設(shè)置--> <solid android:color="@android:color/white"/> <!--圓角設(shè)置--> <corners android:radius="15dp"/> </shape>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android getBackground().setAlpha遇到問題解決辦法
這篇文章主要介紹了Android getBackground().setAlpha遇到問題解決辦法的相關(guān)資料用,getBackground().setAlpha,導(dǎo)致其他布局背景透明度都改變的問題,需要的朋友可以參考下2017-03-03Android中使用ViewStub實(shí)現(xiàn)布局優(yōu)化
ViewStub是Android布局優(yōu)化中一個(gè)很不錯(cuò)的標(biāo)簽/控件,直接繼承自View。雖然Android開發(fā)人員基本上都聽說過,但是真正用的可能不多。今天我們就來詳細(xì)探討下ViewStub的使用2016-09-09ListView的Adapter使用(綁定數(shù)據(jù)) 之 自定義每一項(xiàng)的布局去綁定數(shù)據(jù)
之前寫的綁定數(shù)據(jù)是只是簡單的綁定了字符串,這次我們將一次綁定多條數(shù)據(jù)并且嘗試用自定義的布局。在這篇文章中首先講解的是用Hashmap 去綁定數(shù)據(jù),第二個(gè)例子,講解自定義布局然后綁定數(shù)據(jù)2013-06-06Android studio 出現(xiàn)錯(cuò)誤Run with --stacktrace option to get the s
這篇文章主要介紹了 Android studio 出現(xiàn)錯(cuò)誤Run with --stacktrace option to get the stack trace. Run with --info or --debu的相關(guān)資料,需要的朋友可以參考下2016-11-11Android實(shí)現(xiàn)viewpager實(shí)現(xiàn)循環(huán)輪播效果
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)viewpager實(shí)現(xiàn)循環(huán)輪播效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-03-03Android編程基于重力傳感器實(shí)現(xiàn)橫豎屏放向切換功能
這篇文章主要介紹了Android編程基于重力傳感器實(shí)現(xiàn)橫豎屏放向切換功能,結(jié)合具體實(shí)例形式分析了Android基于重力傳感器實(shí)現(xiàn)橫豎屏切換的相關(guān)操作技巧,需要的朋友可以參考下2018-01-01android md5加密與rsa加解密實(shí)現(xiàn)代碼
本文將詳細(xì)介紹android上的MD5和RSA的加解密實(shí)現(xiàn)代碼分享,需要了解更多的朋友可以參考下2012-12-12Android EditText 監(jiān)聽用戶輸入完成的實(shí)例
下面小編就為大家分享一篇Android EditText 監(jiān)聽用戶輸入完成的實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-02-02Android檢測手機(jī)中存儲(chǔ)卡及剩余空間大小的方法(基于Environment,StatFs及DecimalFormat
這篇文章主要介紹了Android檢測手機(jī)中存儲(chǔ)卡及剩余空間大小的方法,基于Environment,StatFs及DecimalFormat實(shí)現(xiàn)該功能,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-01-01