1

在我的應用程序中,我在對話框中顯示圖像。如果用戶按下按鈕,則出現對話框並佔用整個屏幕的80%。背景將變暗,因爲這是Android對話框的默認行爲。對話框:除一些區域以外的所有其他區域

Dialog dialog = new Dialog(ActQuiz.this); 
       dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
       dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); 
       dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { 
        @Override 
        public void onDismiss(DialogInterface dialogInterface) { 
         //nothing; 
        } 
       }); 

       int width = (int) (getResources().getDisplayMetrics().widthPixels * 0.80); 
       int height = (int) (getResources().getDisplayMetrics().heightPixels * 0.80); 
       dialog.getWindow().setLayout(width, height); 
       ImageView imageView = new ImageView(ActQuiz.this); 
       String uri = "@drawable/" + info.getInfopicture(); 
       int imageResource = getResources().getIdentifier(uri, null, getPackageName()); 
       Drawable myDrawable = ContextCompat.getDrawable(ActQuiz.this, imageResource); 
       imageView.setImageDrawable(myDrawable); 
       new PhotoViewAttacher(imageView); 
       dialog.addContentView(imageView, new RelativeLayout.LayoutParams(width, height)); 
       dialog.show(); 

所以我想實現是禁用調光的按鈕,這是對話框後面可見。

enter image description here

這是可能的,或者我只能去除調光整個背景是什麼?

+0

您可以清除對話框背後的暗淡背景......是嗎? – rafsanahmad007

+0

您可能的意思是:clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHI ND)。但它會消除整個背景的調光。我只想要它的按鈕。你可以在我的帖子中看到它。 –

+0

你可以看看這個:https://stackoverflow.com/questions/14030154/how-to-dim-blur-only-part-of-the-screen – rafsanahmad007

回答

1

這是可能的還是我可以只刪除整個背景的調光?

無法指示Dialog將除某些視圖或某個區域之外的所有內容調暗。沒有這樣的API來做到這一點。

你可以做什麼,是提供你的自定義drawable作爲背景Dialog的窗口。該可繪製的將被給出Rect,座標爲Button和屏幕的Rect。除了提供的矩形之外,它會在任何地方繪製暗淡(基本上是半透明的黑色)。看起來像xfermode SrcOut是應該應用的模式。

相關問題