是否可以在 Android 应用程序中仅显示一个图像弹出/出现?它类似于覆盖 AlertDialog 的普通视图,因此它只包含一个图像而没有其他内容.
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.
解决方案: 感谢@blessenm 的帮助,我找到了答案.将活动屏蔽为对话框似乎是理想的方式.以下是我使用的代码.应用程序可以根据需要调用此对话框样式的活动,就像启动新活动一样
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>
为 Activity 设置以下样式以完成此操作至关重要:
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>
最后一步是在清单中为 Activity 声明此样式,如下所示:
<activity android:name=".ImageDialog" android:theme="@style/myDialogTheme" />
如果你只是想使用一个普通的对话框,像这样应该可以工作
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
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>
这篇关于Android 图像对话框/弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!