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>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android Flutter圖片處理之高斯模糊的實(shí)現(xiàn)
這篇文章主要為大家詳細(xì)介紹了如何利用Android Flutter實(shí)現(xiàn)高斯模糊效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08
Android性能測(cè)試關(guān)注的指標(biāo)整理
在本篇文章里小編給各位整理的是關(guān)于Android性能測(cè)試關(guān)注的指標(biāo)整理內(nèi)容,有興趣的朋友們學(xué)習(xí)下。2019-10-10
RecyclerView進(jìn)階:使用ItemTouchHelper實(shí)現(xiàn)拖拽和側(cè)滑刪除效果
現(xiàn)在RecyclerView的應(yīng)用越來越廣泛了,本篇文章主要介紹了RecyclerView進(jìn)階:使用ItemTouchHelper實(shí)現(xiàn)拖拽和側(cè)滑刪除效果,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-02-02
Android編程之九宮格實(shí)現(xiàn)方法實(shí)例分析
這篇文章主要介紹了Android編程之九宮格實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了Android九宮格的實(shí)現(xiàn)方法與具體步驟,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-01-01
Android?studio?利用共享存儲(chǔ)進(jìn)行用戶的注冊(cè)和登錄驗(yàn)證功能
這篇文章主要介紹了Android?studio?利用共享存儲(chǔ)進(jìn)行用戶的注冊(cè)和登錄驗(yàn)證功能,包括注冊(cè)頁面布局及登錄頁面功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2021-12-12
Android開發(fā)中MotionEvent坐標(biāo)獲取方法分析
這篇文章主要介紹了Android開發(fā)中MotionEvent坐標(biāo)獲取方法,結(jié)合實(shí)例形式分析了MotionEvent獲取坐標(biāo)的相關(guān)函數(shù)使用方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下2016-02-02
Android連接MySQL數(shù)據(jù)庫(kù)詳細(xì)教程
在Android應(yīng)用程序中連接 MySQL 數(shù)據(jù)庫(kù)可以幫助開發(fā)人員實(shí)現(xiàn)更豐富的數(shù)據(jù)管理功能,本教程將介紹如何在Android應(yīng)用程序中使用低版本的MySQL Connector/J驅(qū)動(dòng)程序來連接MySQL數(shù)據(jù)庫(kù),需要的朋友可以參考下2023-05-05
AndroidStudio修改Code Style來格式化自定義標(biāo)簽的xml文件方式
這篇文章主要介紹了AndroidStudio修改Code Style來格式化自定義標(biāo)簽的xml文件方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-03-03

