導航:首頁 > 操作系統 > androiddialog模糊

androiddialog模糊

發布時間:2022-11-28 18:35:22

android創建dialog時如何去掉模糊的背景

有函數啊 可以查查啊

例如:
一:控制Dialog 的背景方法:1.定義一個無背景主題主題<!--去掉背景Dialog-->
<style name="NobackDialog"
parent="@android:style/Theme.Dialog">
<item
name="android:windowBackground">@color/no_back</item>
</style>
2.創建Dialog
dialog = new Dialog(this,R.style.dialog);
dialog.setContentView(R.layout.dialog_loading);

or:
dialog = new Dialog(this,R.style.NobackDialog);
LayoutInflater mInflater = LayoutInflater.from(this);
View dialogProcessBar =
mInflater.inflate(R.layout.dialog_loading,null);
dialog.setView(dialogProcessBar,0, 0, 0, 0);

二:控制Dialog 以及內部控制項的背景方法:
dialog = new Dialog(this,R.style.dialog);
WindowManager.LayoutParams lp=dialog.getWindow().getAttributes();
// 模糊度getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
dialog.getWindow().setAttributes(lp);
lp.alpha=0.5f;(0.0-1.0)//透明度,黑暗度為lp.dimAmount=1.0f;

三:去掉邊框、title 等參數
<resources>
<style name="dialog" parent="@android:style/Theme.Dialog">
<item
name="android:windowFrame">@null</item><!--邊框-->
<item
name="android:windowIsFloating">true</item><!--是否浮現在activity之上-->
<item
name="android:windowIsTranslucent">false</item><!--半透明-->
<item name="android:windowNoTitle">true</item>
<item
name="android:background">@android:color/black</item>
<item name="android:windowBackground">@null</item>
<item
name="android:backgroundDimEnabled">false</item><!--模糊-->
</style>
</resources>

⑵ android的dialog問題

button2.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("Move");
// 指定下拉列表的顯示數據
final String[] cities = {"定時瀏覽漫畫", "瀏覽書簽", "漫畫旋轉"};
// 設置一個下拉的列表選擇項
builder.setItems(cities, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
Toast.makeText(MainActivity.this, "選擇的為:" + cities[which], Toast.LENGTH_SHORT).show();
}
});
builder.show();
}
});

⑶ Android dialog 遮住輸入框的解決思路

在工作中經常會遇到彈出的dialog有輸入框的情況,屏幕大了還好,屏幕小了之後就特別容易出現輸入框被軟鍵盤遮住的情況,下面就是我在實際想中中遇到的

從上圖可以看出輸入框已經看不到了,遇到這種情況的第一個思路都是在dialog的style中添加

<item name="android:windowSoftInputMode">adjustPan</item>,我也試了下基本上沒用。然後換了個思路,既然軟鍵盤彈出來了,為什麼不能讓dialog向上移動同樣的距離呢。思路有了,下面就是把他實現了。

首先就是要計算軟鍵盤的高度,由於google並沒有給出具體的方法來計算軟鍵盤的高度,這時候我們就只能根據布局的高度變化來計算了。首先需要計算出屏幕的bottom坐標,然後監控布局的變動判斷變動後的bottom和初始的bottom的差值,一般肉眼觀察軟鍵盤的高度差不多是屏幕高度的1/3,所以就假設bottom往上移動了屏幕的1/3的距離就認為軟體盤彈出來了,當然也可以根據其他值來判斷,下面貼出具體方法:

/**

* activity中判斷軟鍵盤是否顯示

* @param activity

* */

fun isKeyboardShowing(activity: Activity): Boolean {

val screenHeight = activity.window!!.decorView.height.toDouble()

//獲取view的可見區域

    val rect = Rect()

activity.window!!.decorView.getWindowVisibleDisplayFrame(rect)

return (2.0 /3.0) * screenHeight > rect.bottom.toDouble()

}

接下來我們來計算出軟體盤的高度,經過我在多個測試機上實驗發現初始時bottom就是屏幕的高度,下面是計算鍵盤高度的具體方法

/**

* activity中計算軟鍵盤的高度

* @param activity

* */

fun getKeyboardHeight(activity: Activity): Int {

val displayMetrics = DisplayMetrics()

activity.windowManager.defaultDisplay.getMetrics(displayMetrics)

val screenHeight = displayMetrics.heightPixels

    val rect = Rect()

activity.window!!.decorView.getWindowVisibleDisplayFrame(rect)

return screenHeight - rect.bottom

}

有了高度之後一切就好辦了我們只需要在軟鍵盤彈出來的時候把dialog往上移動就行,在移動方式上我選擇了設置LayoutParams的方式,開始時想設置底部margin的,結果發現沒作用,dialog一點不移動,最後只好設置上邊的margin為負值

if (SoftUtils.isKeyboardShowing(context)) {

val lp =mRootView.layoutParams as ViewGroup.MarginLayoutParams

if (lp.topMargin ==0) {

lp.topMargin = -SoftUtils.getKeyboardHeight(context)

if (mRootView.height

lp.height =mRootOriginHeight

        }

mRootView.layoutParams = lp

}

}else {

if (mRootOriginHeight ==0) {

mRootOriginHeight =mRootView.height

    }

val lp =mRootView.layoutParams as ViewGroup.MarginLayoutParams

if (lp.topMargin <0) {

lp.topMargin =0

        mRootView.layoutParams = lp

}

}

其中mRootView是dialog最外層的布局。在這裡面比較重要的一點監測方式,在哪裡監測軟鍵盤的彈出動作,在activity中可以監測onWindowFocusChanged方法,但是如果封裝了dialog的話,dialog中的onWindowFocusChanged並不會起作用,在這里我選擇了使用ViewTreeObserver和監聽,通過給mRootView的ViewTreeObserver添加addOnGlobalLayoutListener來實時判斷,下面是完整的方法

private fun setSpace() {

val treeObserver =mRootView.viewTreeObserver

    treeObserver.addOnGlobalLayoutListener{

        if (SoftUtils.isKeyboardShowing(context)) {

val lp =mRootView.layoutParams as ViewGroup.MarginLayoutParams

if (lp.topMargin ==0) {

lp.topMargin = -SoftUtils.getKeyboardHeight(context)

if (mRootView.height

lp.height =mRootOriginHeight

                }

mRootView.layoutParams = lp

}

}else {

if (mRootOriginHeight ==0) {

mRootOriginHeight =mRootView.height

            }

val lp =mRootView.layoutParams as ViewGroup.MarginLayoutParams

if (lp.topMargin <0) {

lp.topMargin =0

                mRootView.layoutParams = lp

}

}

}

}

在這里當軟鍵盤彈出的時候重新設置了下dialog的高度,因為有時候軟鍵盤的彈出會使dialog的高度壓縮,所以彈出的時候重新設置下就好了。

這就是我的一個解決思路,當然完全按這個寫的話當輸入框較多時也可能出問題,最上層的輸入框跑屏幕之外去了,這種情況下我們只需要根據輸入框的位置動態的計算dialog需要往上移動的距離就行,不要一直設置為計算出來的軟鍵盤的高度。

下圖是解決之後的UI

⑷ android 如何讓一個dialog的背景為透明

北京設置透明?你可以設置dialog的樣式,通過Style 來設置;
Android Dialog背景全透明無邊框 Theme Style
<style name="Translucent_NoTitle" parent="android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:background">#00000000</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
</style>

⑸ 安卓開發怎樣把dialog的背景設置成透明的

按如下步驟操作即可: 1、自定義Dialog public class SelectDialog extends AlertDialog{ public SelectDialog(Context context, int theme) { super(context, theme); } public SelectDialog(Context context) { super(context); } @Override protected void onCreate(Bundle savedInstanceState) { super/apk/res/android" android:orientation="vertical" android:padding="10dp" android:layout_width="115dp" android:layout_height="wrap_content" android:background="@color/blue"> <Button android:layout_height="wrap_content" android:background="#00000000" android:layout_width="fill_parent" android:text="全部聯系人" android:paddingTop="5dp" android:paddingBottom="5dp" android:paddingLeft="10dp" android:gravity="leftcenter_vertical" android:id="@+id/btnSltCntAll"></Button> <Button android:layout_height="wrap_content" android:background="#00000000" style="@drawable/greenhand_button" android:text="咕咚用戶" android:gravity="leftcenter_vertical" android:paddingBottom="5dp" android:paddingTop="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:layout_width="fill_parent" android:id="@+id/btnSltGudongUser"></Button> <Button style="@drawable/greenhand_button" android:background="#00000000" android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="推薦用戶" android:gravity="leftcenter_vertical" android:paddingTop="5dp" android:paddingBottom="5dp" android:paddingLeft="10dp" android:id="@+id/btnSltRecommend"></Button> </LinearLayout> 3、顏色color.xml代碼 <?xml version="1.0" encoding="utf-8"?> <resources> <color name="transparent">#00000000</color> </resources> 4、樣式style.xml代碼 <?xml version="1.0" encoding="utf-8"?> <resources> <style name="dialog" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item><!--邊框--> <item name="android:windowIsFloating">true</item><!--是否浮現在activity之上--> <item name="android:windowIsTranslucent">false</item><!--半透明--> <item name="android:windowNoTitle">true</item><!--無標題--> <item name="android:windowBackground">@color/transparent</item><!--背景透明--> <item name="android:backgroundDimEnabled">false</item><!--模糊--> </style> </resources> 4、顯示Dialog SelectDialog selectDialog = new SelectDialog(this,R.style.dialog);//創建Dialog並設置樣式主題 Window win = selectDialog.getWindow(); LayoutParams params = new LayoutParams(); params.x = -80;//設置x坐標 params.y = -60;//設置y坐標 win.setAttributes(params); selectDialog.setCanceledOnTouchOutside(true);//設置點擊Dialog外部任意區域關閉Dialog selectDialog.show();

⑹ 如何使Android dialog彈出後的Android activity背景不變暗

第一種是在樣式文件styles.xml中添加新的樣式,父樣式指向的是默認的Dialog樣式,修改如下,然後你的Dialog用你添加的樣式就可以了.
<resources>
<style name="DialogStyle" parent="@android:style/Theme.Dialog">
<!-- dialog背景樣式 -->
<item name="android:windowBackground"> @android:color/transparent </item>
<!-- 背景透明 -->
<item name="android:backgroundDimEnabled">false</item> </style>
</resources>
第二種是在代碼中修改.lp.alpha大小隨自己要求設置
// 設置屏幕背景變暗
private void setScreenBgDarken() {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.alpha = 0.5f;
lp.dimAmount = 0.5f;
getWindow().setAttributes(lp);
}
// 設置屏幕背景變亮
private void setScreenBgLight() {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.alpha = 1.0f;
lp.dimAmount = 1.0f;
getWindow().setAttributes(lp);
}
第三種是重寫在Activity中onCreateDialog()方法,這種我沒用過,你可以嘗試一下.

⑺ android怎麼修改系統dialog風格

1、編寫一個文本樣式。

DIALOG的標題是一個textview,在sytles.xml中,添加如下代碼來設置你自己的文本樣式:

?

<style name="DialogWindowTitle">

<item name="android:textSize">22sp</item>

<item name="android:textColor">@color/font_dark_grey</item>

</style>

2、設置對話框的標題主題。

上面的標題文本並不能直接設置為對話框的標題樣式。 我們還需要編寫一個表示標題的主題的style,在這里指定標題的文本樣式。代碼如下:

?

<style name="DialogWindowTitle.DeviceDefault">

<item name="android:maxLines">1</item>

<item name="android:scrollHorizontally">true</item>

<item name="android:textAppearance">@style/DialogWindowTitle</item>

</style>

3、設置對話框主題。

接下來,我們編寫我們的對話框主題,在這里指定標題的主題。由於一些屬性並不是public的,所以我們需要繼承自原來的某個style,代碼如下:

?

<!--Dialog主題-->

<style name="Theme.DeviceDefault.Dialog" parent="@android:style/Theme.DeviceDefault.Light.Dialog">

<item name="android:windowTitleStyle">@style/DialogWindowTitle.DeviceDefault</item>

</style>

4、自定義App的主題。

接下來,我們需要在我們的App theme中指定我們的對話框使用這種主題,所以需要定義一個App theme。同樣由於App theme的許多屬性並不是public的(比如下面要提到的標題下面的那條藍線),所以我們要繼承自一個原生的style。這里我根據程序需要選擇了Theme.Holo.Light.NoActionBar,代碼如下:

?

<style name="ParkingTheme" parent="@android:style/Theme.Holo.Light.NoActionBar">

<item name="android:dialogTheme">@style/Theme.DeviceDefault.Dialog</item>

</style>

5、指定App主題。

最後一步,我們需要在AndroidManifest.xml文件中,指定我們的app主題。這步很簡單,只需要在application標簽中指定android:theme的值即可,如下:

?

android:theme="@style/ParkingTheme"

不過這只是指定了Dialog的主題。如果是通過AlertDialog創建出來的對話框,主題還是原來的。所以我們還需要以下步驟。

7、編寫AlertDialog主題。

我們無法直接繼承系統主題里的AlertDialog的style。如把parent指定為Theme.DeviceDefault.Dialog.Alert,Theme.Holo.Dialog.Alert,Theme.DeviceDefault.Light.Dialog.Alert或Theme.Holo.Light.Dialog.Alert,都會導致編譯不過。所以我們需要繼承自Dialog的style。在這里我以Theme.Holo.Light.Dialog為例,代碼如下:

<!--AlderDialog主題-->

<style name="Theme.DeviceDefault.Dialog.Alert" parent="@android:style/Theme.Holo.Light.Dialog">

<item name="android:windowBackground">@android:color/transparent</item>

<item name="android:windowTitleStyle">@style/DialogWindowTitle.DeviceDefault</item>

<item name="android:windowContentOverlay">@null</item>

<item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>

<item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>

</style>

在這里我參考了原生的alertDialog的style,設定了窗口背景為透明,以及windowContentOverlay為null這兩個重要屬性,否則你會看到在AlertDialog下面還有一層對話框的背景,或者是對話框的背景遮住了所有內容這樣的問題存在。

8、指定AlertDialog的主題。

我們需要在第4步所說的自定義的AppTheme中,添加一行代碼來指定要使用的AlertDialog的style,代碼如下:

?

<item name="android:alertDialogTheme">@style/Theme.DeviceDefault.Dialog.Alert</item>

9、修改標題下面的藍色線。

如果你修改了對話框的主題顏色,那麼標題下面的藍色的線肯定會讓你很郁悶。如果對話框較少,你可以選擇隱藏標題,然後自定義一個包含了標題的View來設置為對話框的內容。但是如果你的對話框有許多種,而且本來都是可以調用原來的API就來生成的話,要去定義這么多個帶標題的view,這樣做下來心裡肯定是很糾結的。

標題下面的藍色的線,並不是在Dialog或AlertDialog中設置或通過它們的style中定義的。它是定義在各種風格的dialog的layout當中,然後再在AppTheme裡面指定dialog的對應屬性。遺憾的是,目前我看到這幾個相關屬性還不是public的,不能自己設置,所以只有通過Java代碼來實現了。

表示這條藍色的線的叫做titleDivider,我們可以通過getResources()的API來獲取它的IP,然後設置顏色。代碼如下:

?

public static final void dialogTitleLineColor(Dialog dialog, int color) {

Context context = dialog.getContext();

int divierId = context.getResources().getIdentifier("android:id/titleDivider", null, null);

View divider = dialog.findViewById(divierId);

divider.setBackgroundColor(color);

⑻ android設置dialog在第幾層顯示

android中dialog都是彈出的對話框,沒有第幾層這個概念,只有dialog有級別。
具體實現代碼:
1.創建對象框
AlertDialog.Builder builder = new Builder(context);
builder.setTitle("請輸入"); //設置對話框標題
builder.setIcon(android.R.drawable.btn_star); //設置對話框標題前的圖標

2.創建EditText輸入框
final EditText edit = new EditText(context);

3.將輸入框賦值給Dialog,並增加確定取消按鍵
builder.setView(edit);
builder.setPositiveButton("確認", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(context, "你輸入的是: " + edit.getText().toString(), Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(context, "你點了取消", Toast.LENGTH_SHORT).show();
}
});

4.設置常用api,並show彈出
builder.setCancelable(true); //設置按鈕是否可以按返回鍵取消,false則不可以取消
AlertDialog dialog = builder.create(); //創建對話框
dialog.setCanceledOnTouchOutside(true); //設置彈出框失去焦點是否隱藏,即點擊屏蔽其它地方是否隱藏
dialog.show();

⑼ 如何解決android 5.0 dialog背景無法透明的問題

dialog裡面對應的屬性,可以在activty載入完之後,設置一下:
dlg.getWindow().setBackgroundDrawable(new ColorDrawable())

⑽ android 怎樣設置dialog的背景

[html]viewplainprint?
<itemname="android:windowFrame">@null</item>

閱讀全文

與androiddialog模糊相關的資料

熱點內容
dvd光碟存儲漢子演算法 瀏覽:757
蘋果郵件無法連接伺服器地址 瀏覽:962
phpffmpeg轉碼 瀏覽:671
長沙好玩的解壓項目 瀏覽:144
專屬學情分析報告是什麼app 瀏覽:564
php工程部署 瀏覽:833
android全屏透明 瀏覽:736
阿里雲伺服器已開通怎麼辦 瀏覽:803
光遇為什麼登錄時伺服器已滿 瀏覽:302
PDF分析 瀏覽:484
h3c光纖全工半全工設置命令 瀏覽:143
公司法pdf下載 瀏覽:381
linuxmarkdown 瀏覽:350
華為手機怎麼多選文件夾 瀏覽:683
如何取消命令方塊指令 瀏覽:349
風翼app為什麼進不去了 瀏覽:778
im4java壓縮圖片 瀏覽:362
數據查詢網站源碼 瀏覽:150
伊克塞爾文檔怎麼進行加密 瀏覽:892
app轉賬是什麼 瀏覽:163