Is it possible to have just an image popup/come-up in an Android application? It's similar to an overriding the normal view of an AlertDialog so that it contains just an image and nothing else.
SOLUTION: I was able to find an answer thanks to @blessenm's help. Masking an activity as a dialog seems to be the ideal way. The following is the code that I have used. This dialog styled activity can be invoked as needed by the application the same way a new activity would be started
ImageDialog.java
public class ImageDialog extends Activity { private ImageView mDialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.your_dialog_layout); mDialog = (ImageView)findViewById(R.id.your_image); mDialog.setClickable(true); //finish the activity (dismiss the image dialog) if the user clicks //anywhere on the image mDialog.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { finish(); } }); } }
your_dialog_layout.xml
<?xml version="1.0" encoding="UTF-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/image_dialog_root" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@android:color/transparent" android:gravity = "center"> <ImageView android:id="@+id/your_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src = "@drawable/your_image_drawable"/> </FrameLayout>
It is crucial that you set the following style for the activity to accomplish this:
styles.xml
<style name="myDialogTheme" parent="@android:style/Theme.Dialog"> <item name="android:windowNoTitle">true</item> <item name="android:windowFrame">@null</item> <item name="android:background">@android:color/transparent</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowIsFloating">true</item> <item name="android:backgroundDimEnabled">false</item> <item name="android:windowContentOverlay">@null</item> </style>
The final step is to declare this style for the activity in the manifest as follows:
<activity android:name=".ImageDialog" android:theme="@style/myDialogTheme" />
Show image as a popup on a click event or any event. Simply set the image as drawable and thats it!!!. And also you can set width, height & background color as you want.
A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed. Dialog Design.
setTitle(CharSequence title)AlertDialog alertDialog = alertDialogBuilder. create(); alertDialog. show(); This will create the alert dialog and will show it on the screen.
No xml:
public void showImage() { Dialog builder = new Dialog(this); builder.requestWindowFeature(Window.FEATURE_NO_TITLE); builder.getWindow().setBackgroundDrawable( new ColorDrawable(android.graphics.Color.TRANSPARENT)); builder.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { //nothing; } }); ImageView imageView = new ImageView(this); imageView.setImageURI(imageUri); builder.addContentView(imageView, new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); builder.show(); }
If you just want to use a normal dialog something like this should work
Dialog settingsDialog = new Dialog(this); settingsDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); settingsDialog.setContentView(getLayoutInflater().inflate(R.layout.image_layout , null)); settingsDialog.show();
image_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="YOUR IMAGE"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="OK" android:onClick="dismissListener"/> </LinearLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With