0

I have a dialog-style activity that appears over my main activity in an Android application. How can I get the background to be translucent? Not transparent, but translucent - say 70% opaque. I've tried applying this theme to the activity:

 <style name="Theme.Transparent" parent="android:Theme"> <item name="android:windowIsTranslucent">true</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsFloating">true</item> <item name="android:backgroundDimEnabled">false</item> </style> 

and several variations on this but still the dialog activity appears 100% opaque. Also, the layout xml of the activity itself (and elements displayed on it), specify a background of "#70000000".

1 Answer 1

3

For totally transparent dialog you can use this :

Step 1> Create a colors.xml file in the ‘values’ folder under ‘res’ and add the following line..

<drawable name="transparent">#00000000</drawable> 

Step 2> Create a styles.xml file in the ‘values’ folder under ‘res’ and the following lines…

<style name="Transparent"> <item name="android:windowIsTranslucent">true</item> <item name="android:windowAnimationStyle"> @android:style/Animation.Translucent </item> <item name="android:windowBackground">@drawable/transparent</item> <item name="android:windowNoTitle">true</item> <item name="android:colorForeground">#fff</item> </style> 

(I guess the tags and attributes are self explanatory…)

Step 3> Actually, that's it……………………

Let’s add this to a dialog…..

Step 4> Create a class with the following lines……

public class DialogBox extends Dialog { public DialogBox(Context context, int theme) { super(context, theme); setContentView(R.layout.dialog); okButton = (Button) findViewById(R.id.dialog_OkButton); setListeners(); } } 

(Make sure you create a layout for the dialog)

Step 5> Next create an activity class as follows….

public class T_Temp extends Activity { private DialogBox dialog; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); dialog = new DialogBox(this, R.style.Transparent); dialog.show(); } } 

or you can use this to make dialog attractive to add blur effect ....

Just check this out: there is near about 30% transparency...

 dialog = new AlertDialog.Builder(WordCube.this) .setTitle(WordCube.this.getResources().getString(R.string.app_name)) .setMessage(s) .setIcon(R.drawable.logo) .setPositiveButton(R.string.btn_close, null) .show(); 

Below shows the code needed to add blur and remove dimming of the background (as I think the blur looks nicer when the background is well lit).

view plaincopy to clipboardprint? WindowManager.LayoutParams lp = dialog.getWindow().getAttributes(); lp.dimAmount=0.0f; dialog.getWindow().setAttributes(lp); dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.