How to use an Activity as a Dialog in android java?

It is very easiest way to use an activity as a dialog in android. There is simple 2 step to make it.

1 In your style.xml file add the below code-


<style name="TransparentDialog" parent="Theme.AppCompat.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:layout_gravity">top</item>
<item name="android:windowMinWidthMajor">95%</item>
<item name="android:windowMinWidthMinor">95%</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowCloseOnTouchOutside">true</item>
<item name="android:windowFullscreen">true</item>
</style>




2 In your manifest.xml, which activity you want to make like dialog(If possible this activity only extends "Actvity", try to avoid use "AppCompatActivity" and don't define screenorientation property of this activity. it cause the runtime exception in some device. the screen orientation take the parent activity.), just add the theme and your work is done. just run and see the output.



<activity android:name=".YourActivity"
android:theme="@style/TransparentDialog"/>






No comments:

IRCTC Share Price Declines by 2% Despite 30% Jump in Q4 Net Profit; Board Announces Dividend of INR 2 per Share

Introduction: The share price of Indian Railway Catering and Tourism Corporation (IRCTC) experienced a decline of 2% in today's trading ...