本文介紹了Android 圖像對話框/彈出窗口的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
是否可以在 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 圖像對話框/彈出窗口的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!