Android自定義Dialog內(nèi)部透明、外部遮罩效果
本文實(shí)例為大家分享了Android自定義Dialog遮罩效果的具體代碼,供大家參考,具體內(nèi)容如下
圖例:

代碼
1、自定義dialog:引入樣式和代碼指定樣式
package com.gxjl.pe.gxjlpesdk.view;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import com.gxjl.pe.gxjlpesdk.R;
/**
* 相機(jī)、相冊(cè)選擇 彈框
* Created by xiaoshuai on 2018/8/20.
*/
public abstract class CameraPhotoDialog extends Dialog implements View.OnClickListener{
private Context context;
public CameraPhotoDialog(@NonNull Context context) {
super(context, R.style.dialogTransparent);//內(nèi)容樣式在這里引入
this.context = context;
}
public CameraPhotoDialog(@NonNull Context context, int themeResId) {
super(context, themeResId);
}
protected CameraPhotoDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_camrea_photo);
//tv_title = findViewById(R.id.tv_title);
Window dialogWindow = getWindow();
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
DisplayMetrics d = context.getResources().getDisplayMetrics(); // 獲取屏幕寬、高用
lp.width = (int) (d.widthPixels * 0.9); // 寬度設(shè)置為屏幕寬度的80%
//lp.dimAmount=0.0f;//外圍遮罩透明度0.0f-1.0f
dialogWindow.setAttributes(lp);
dialogWindow.setGravity(Gravity.BOTTOM);//內(nèi)圍區(qū)域底部顯示
}
@Override
public void onClick(View view) {
int i = view.getId();
if (i == R.id.tv_cancel) {
this.dismiss();
}
}
protected abstract void confirm();
}
2、dialog_camrea_photo.xml 布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="@android:color/transparent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_camera_check"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"
android:layout_gravity="center_horizontal"
android:text="拍照"
android:textSize="16sp"
android:textColor="@color/font_007AFF"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/line_ECECED"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"
android:layout_gravity="center_horizontal"
android:text="照片圖庫"
android:textSize="16sp"
android:textColor="@color/font_007AFF"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/bg_camera_check"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"
android:layout_gravity="center_horizontal"
android:text="拍照"
android:textSize="16sp"
android:textColor="@color/font_007AFF"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
3、style.xml 樣式布局:指定dialog內(nèi)容樣式
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="dialogTransparent" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item> <!--邊框--> <item name="android:windowIsFloating">true</item> <!--是否浮現(xiàn)在activity之上--> <item name="android:windowIsTranslucent">true</item> <!--半透明--> <item name="android:windowNoTitle">true</item> <!--無標(biāo)題--> <item name="android:background">@android:color/transparent</item> <!--背景透明--> <item name="android:windowBackground">@android:color/transparent</item> <!--背景透明--> <item name="android:backgroundDimEnabled">true</item> <!--模糊--> <item name="android:backgroundDimAmount">0.6</item> <!--背景透明度--> </style> </resources>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- android自定義Dialog彈框和背景陰影顯示效果
- Android自定義Dialog實(shí)現(xiàn)加載對(duì)話框效果
- Android編程自定義AlertDialog樣式的方法詳解
- 解決Android中自定義DialogFragment解決寬度和高度問題
- Android 自定義AlertDialog對(duì)話框樣式
- Android自定義對(duì)話框Dialog的簡(jiǎn)單實(shí)現(xiàn)
- Android中DialogFragment自定義背景與寬高的方法
- Android編程自定義對(duì)話框(Dialog)位置及大小的方法
- Android自定義Dialog原理實(shí)例解析
相關(guān)文章
Android中應(yīng)用界面主題Theme使用方法和頁面定時(shí)跳轉(zhuǎn)應(yīng)用
在Android SDK中內(nèi)置了下面的Theme,可以按標(biāo)題欄Title Bar和狀態(tài)欄Status Bar是否可見來分類,感興趣的朋友可以了解下哈2013-06-06
Android實(shí)現(xiàn)水波紋擴(kuò)散效果的實(shí)例代碼
這篇文章主要介紹了Android實(shí)現(xiàn)水波紋擴(kuò)散效果的實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-05-05
viewPager+fragment刷新緩存fragment的方法
這篇文章主要介紹了viewPager+fragment刷新緩存fragment的方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-03-03
Android Studio 配置:自定義頭部代碼注釋及添加模版方式
這篇文章主要介紹了Android Studio 配置:自定義頭部代碼注釋及添加模版方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-03-03
Android基于繪制緩沖實(shí)現(xiàn)煙花效果
這篇文章主要介紹了Android基于繪制緩沖實(shí)現(xiàn)煙花效果,文中通過代碼示例和圖文結(jié)合介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,感興趣的同學(xué)可以自己動(dòng)手嘗試一下2024-03-03
Android 多國(guó)語言value文件夾命名的方法
這篇文章主要介紹了Android 多國(guó)語言value文件夾命名的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-03-03

