2011-01-21 65 views
12

如何在淡化背景的對話框周圍刪除此「shadowBox」效果?Android:沒有陰影的對話框

我知道我可以創建像完全自定義的視圖,但我們可以說我想保持簡單。我只有textView和2個按鈕的對話框的xml佈局,我只想爲這個對話框停止淡入淡出。

回答

35

嘗試:

dialog.getWindow().clearFlags(LayoutParams.FLAG_DIM_BEHIND); 
6

創建style.xmlvalues,並把這樣的事情:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<style name="progress_dialog"> 
    <item name="android:windowIsFloating">true</item> 
    <item name="android:windowContentOverlay">@null</item> 
    <item name="android:windowTitleStyle">@null</item> 
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> 
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item> 
    <item name="android:backgroundDimEnabled">false</item> 
    <item name="android:background">#00ffffff</item> 
</style> 

而在最後,把這種風格到您的對話框。

+0

嗯,將其作爲style =「@ style/styled_dialog」應用於我的dialog.xml的linearLayout,而沒有任何內容。 – yosh 2011-01-21 13:31:35

+0

您使用哪個DialoBox?一個進步嗎?或警報對話框?我在使用ProgressDialog時使用了它,並在實例化它時指定了樣式。 – 2011-01-21 17:28:16

+1

@ Sheikh-Aman我正在使用Alert對話框,我無法找到如何添加樣式的方式。 – yosh 2011-01-24 13:03:59

2

在這裏給樣品類

public void showDialog() { 

    Dialog dialog = new Dialog(this); 
    Window window = dialog.getWindow(); 
    window.setBackgroundDrawableResource(android.R.color.transparent); 
    window.requestFeature(window.FEATURE_NO_TITLE); 

    dialog.setContentView(R.layout.sample); 
    ImageView imggameover, imgplayagain; 
    imggameover = (ImageView) dialog.findViewById(R.id.gameover); 
    imgplayagain = (ImageView) dialog.findViewById(R.id.playagain); 
    imgplayagain.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      startActivity(new Intent(getApplicationContext(), random.class)); 
      onStop(); 
      finish(); 
     } 
    }); 
    dialog.show(); 
} 

對話框的佈局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/gameoverlayout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@android:color/transparent" 
    > 
    <ImageView 
     android:id="@+id/gameover" 
     android:layout_width="225dip" 
     android:layout_height="160dip" 
     android:background="@drawable/gameover" 
     ></ImageView> 
    <ImageView 
     android:id="@+id/playagain" 
     android:layout_width="160dip" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="100dip" 
     android:layout_marginTop="100dip" 
     android:background="@drawable/playagain" 
     ></ImageView> 
</RelativeLayout> 
4

只需使用

dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);