欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android自定義彈框Dialog效果

 更新時(shí)間:2022年04月19日 15:27:09   作者:抱著回憶旅行  
這篇文章主要為大家詳細(xì)介紹了Android自定義彈框Dialog效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android自定義彈框Dialog效果的具體代碼,供大家參考,具體內(nèi)容如下

1.dialog_delete.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent">
? ? <RelativeLayout
? ? ? ? android:layout_width="236dp"
? ? ? ? android:layout_height="184dp"
? ? ? ? android:layout_centerHorizontal="true"
? ? ? ? android:layout_centerVertical="true"
? ? ? ? android:background="@drawable/dialog_white_back">
? ? ? ? <TextView
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:text="刪除設(shè)備"
? ? ? ? ? ? android:textColor="#333333"
? ? ? ? ? ? android:textSize="15sp"
? ? ? ? ? ? android:layout_centerHorizontal="true"
? ? ? ? ? ? android:layout_marginTop="13dp"></TextView>
? ? ? ? <ImageView
? ? ? ? ? ? android:id="@+id/delete_close_id"
? ? ? ? ? ? android:layout_width="10dp"
? ? ? ? ? ? android:layout_height="10dp"
? ? ? ? ? ? android:background="@mipmap/login_close_back"
? ? ? ? ? ? android:layout_alignParentRight="true"
? ? ? ? ? ? android:layout_marginTop="16dp"
? ? ? ? ? ? android:layout_marginRight="13dp"></ImageView>
?
? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/delete_device_id"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:text="設(shè)備 ? ID:123456789"
? ? ? ? ? ? android:textColor="#333333"
? ? ? ? ? ? android:textSize="16sp"
? ? ? ? ? ? android:layout_marginTop="75dp"
? ? ? ? ? ? android:layout_centerHorizontal="true"></TextView>
?
? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/delete_cancle_id"
? ? ? ? ? ? android:layout_width="77dp"
? ? ? ? ? ? android:layout_height="26dp"
? ? ? ? ? ? android:background="@drawable/round_gray"
? ? ? ? ? ? android:layout_alignParentBottom="true"
? ? ? ? ? ? android:layout_marginBottom="18dp"
? ? ? ? ? ? android:layout_marginLeft="31dp"
? ? ? ? ? ? android:text="取消"
? ? ? ? ? ? android:textSize="11sp"
? ? ? ? ? ? android:textColor="#333333"
? ? ? ? ? ? android:gravity="center"></TextView>
?
? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/delete_sure_id"
? ? ? ? ? ? android:layout_width="77dp"
? ? ? ? ? ? android:layout_height="26dp"
? ? ? ? ? ? android:background="@drawable/round_blue"
? ? ? ? ? ? android:layout_alignParentBottom="true"
? ? ? ? ? ? android:layout_marginBottom="18dp"
? ? ? ? ? ? android:layout_alignParentRight="true"
? ? ? ? ? ? android:layout_marginRight="32dp"
? ? ? ? ? ? android:text="確定"
? ? ? ? ? ? android:textSize="11sp"
? ? ? ? ? ? android:textColor="#FEFDFD"
? ? ? ? ? ? android:gravity="center"></TextView>
? ? </RelativeLayout>
</RelativeLayout>

2.設(shè)置背景邊框,在drawable創(chuàng)建dialog_white_back.xml

顏色以及圓角 根據(jù)自己需求修改

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
? ? android:shape="rectangle">
?
? ? <solid android:color ="#ffffff"/>
? ? <corners
? ? ? ? android:radius="8dp"/>
</shape>

3.按鈕的背景邊框,在drawable創(chuàng)建round_gray.xml

顏色以及圓角 根據(jù)自己需求修改

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
? ? android:shape="rectangle">
?
? ? <solid android:color = "#DCDCDC" />
? ? <corners
? ? ? ? android:radius="360dp"/>
</shape>

4.在Style文件中添加

<!--Dialog 樣式 -->
? ? <style name="BottomDialog" parent="AlertDialog.AppCompat">
? ? ? ? <item name="android:windowIsFloating">true</item>
? ? ? ? <item name="android:windowFrame">@null</item>
? ? ? ? <item name="android:windowNoTitle">true</item>
? ? ? ? <item name="android:windowBackground">@android:color/transparent</item>
? ? ? ? <item name="android:backgroundDimEnabled">true</item>
? ? ? ? <item name="android:windowContentOverlay">@null</item>
? ? ? ? <item name="android:fullBright">@color/clear</item>
? ? ? ? <item name="android:fullDark">@color/clear</item>
? ? ? ? <item name="android:topBright">@color/clear</item>
? ? ? ? <item name="android:topDark">@color/clear</item>
? ? ? ? <item name="android:borderlessButtonStyle">@color/clear</item>
</style>

5.Java代碼部分

/**
? ? ?* 刪除AlertDialog
? ? ?*/
? ? public void DeleteDialog() {
? ? ? ? //布局、id
? ? ? ? View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_delete, null);
? ? ? ? ImageView delete_close_id = view.findViewById(R.id.delete_close_id);
? ? ? ? TextView delete_device_id = view.findViewById(R.id.delete_device_id);
? ? ? ? TextView delete_cancle_id = view.findViewById(R.id.delete_cancle_id);
? ? ? ? TextView delete_sure_id = view.findViewById(R.id.delete_sure_id);
? ? ? ? //顯示樣式
? ? ? ? final Dialog dialog = new Dialog(getActivity(), R.style.BottomDialog);
? ? ? ? dialog.setContentView(view);
? ? ? ? dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
?
? ? ? ? DisplayMetrics dm = getResources().getDisplayMetrics();
? ? ? ? int displayWidth = dm.widthPixels;
? ? ? ? int displayHeight = dm.heightPixels;
? ? ? ? android.view.WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); //獲取對(duì)話框當(dāng)前的參數(shù)值
? ? ? ? p.width = (int) (displayWidth * 0.8); //寬度設(shè)置為屏幕的0.5
? ? ? ? //dialog.setCanceledOnTouchOutside(false);// 設(shè)置點(diǎn)擊屏幕Dialog不消失
? ? ? ? dialog.getWindow().setAttributes(p); ?//設(shè)置生效
? ? ? ? dialog.show();
? ? ? ? //點(diǎn)擊關(guān)閉
? ? ? ? delete_close_id.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? dialog.dismiss();
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? //點(diǎn)擊確定刪除
? ? ? ? delete_sure_id.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? dialog.dismiss();
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? //點(diǎn)擊取消刪除
? ? ? ? delete_cancle_id.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onClick(View v) {
? ? ? ? ? ? ? ? dialog.dismiss();
? ? ? ? ? ? }
? ? ? ? });
? ? }

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論