问题描述
时有可能有只是一个形象弹出/进来,在Android应用程序?它类似于一个压倒一切的AlertDialog的普通视图,以便它包含只是一个形象而已。
解决方法: 我能找到一个答案感谢@ blessenm的帮助。掩蔽的活性作为对话似乎是理想的方式。以下是我已经使用了code。该对话框风格活性可根据需要由应用程序以相同的方式一个新的活动将被开始调用的
ImageDialog.java
公共类ImageDialog延伸活动{
私人ImageView的mDialog;
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.your_dialog_layout);
mDialog =(ImageView的)findViewById(R.id.your_image);
mDialog.setClickable(真正的);
//完成活动(驳回图像对话框),如果用户点击
//在图像上的任意位置
mDialog.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
完();
}
});
}
}
your_dialog_layout.xml
< XML版本=1.0编码=UTF-8&GT?;
<的FrameLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / image_dialog_root
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:背景=@机器人:彩色/透明
机器人:重力=中心>
< ImageView的
机器人:ID =@ + ID / your_image
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:SRC =@可绘制/ your_image_drawable/>
< /的FrameLayout>
这是你设置以下样式的活动来完成这项重要的:的
styles.xml
<样式名称=myDialogTheme父=@安卓风格/ Theme.Dialog>
<项目名称=机器人:windowNoTitle>真< /项目>
<项目名称=机器人:窗框> @空< /项目>
<项目名称=机器人:背景> @android:彩色/透明< /项目>
<项目名称=机器人:windowBackground> @android:彩色/透明< /项目>
<项目名称=机器人:windowIsFloating>真< /项目>
<项目名称=机器人:backgroundDimEnabled>假< /项目>
<项目名称=机器人:windowContentOverlay> @空< /项目>
< /风格>
的最后一步是声明这种风格在清单中的活动如下:的
<活动机器人:名称=机器人ImageDialog。:主题=@风格/ myDialogTheme/>
如果你只是想用一个notmal对话这样的事情应该工作
对话settingsDialog =新的对话框(本);
settingsDialog.getWindow()requestFeature(Window.FEATURE_NO_TITLE)。
settingsDialog.setContentView(getLayoutInflater()。膨胀(R.layout.image_layout
, 空值));
settingsDialog.show();
image_layout.xml
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直>
< ImageView的机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT机器人:SRC =你的形象/>
<按钮机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT
机器人:文本=OK安卓的onClick =dismissListener/>
< / LinearLayout中>
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" />
If you just want to use a notmal 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>
这篇关于Android的图像对话框/弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!