[英]Pop up in android application
I want to display a popup like screen when I click on version icon in the menuitem
. 当我单击
menuitem
版本图标时,我想显示类似屏幕的弹出窗口。 kindly explain how can I achieve this ? 请解释一下我该如何实现?
Hi what you can do is you can invoke an activity normally as generally the corresponding activity declaration in the AndroidManifest.xml file looks like as follows: 嗨,您可以做的是,通常可以正常调用活动,通常AndroidManifest.xml文件中的相应活动声明如下所示:
<activity
android:name="com.aexample.YoursActivity"
android:label="@string/activity_name" >
</activity>
However, there is small trick that can be done to make any activity take on a Dialog form. 但是,可以做一些小技巧来使任何活动都采用对话框形式。 For example, if we change the activity declaration in the AndroidManifest.xml file to this:
例如,如果我们将AndroidManifest.xml文件中的活动声明更改为:
<activity
android:name="com.aexample.YoursActivity"
android:theme="@android:style/Theme.Holo.Dialog"
android:label="@string/activity_name" >
</activity>
What this android:theme="@android:style/Theme.Holo.Dialog"
does is change the theme of an activity. android:theme="@android:style/Theme.Holo.Dialog"
作用是更改活动的主题。 It's still a complete activity, but it has taken on a dialog form. 它仍然是一项完整的活动,但是它采用了对话框形式。
also what you can do is you can work around AlertDialog, the following example shows you how to display an alert box in Android 另外,您可以做的是可以解决AlertDialog,下面的示例向您展示如何在Android中显示警报框
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set title
alertDialogBuilder.setTitle("Your Title");
// set dialog message
alertDialogBuilder
.setMessage("Click yes to exit!")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
MainActivity.this.finish();
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
I did something similar to this. 我做了类似的事情。 I used dialog activity for that.
我为此使用了对话框活动 。 What you have to do is use
parent="@android:style/Theme.Holo.Dialog
in the theme for that activity. 您要做的是在该活动的主题中使用
parent="@android:style/Theme.Holo.Dialog
。
/**
* Method to get a dialog with title, message and one button
*
* @param context
* @param title
* @param message
* @param positiveText
* @return AlertDialog
*/
public static AlertDialog getAlertDialog(Context context, String title,
String message, String positiveText) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
/* builder. */
builder.setMessage(message)
.setTitle(title)
.setCancelable(true)
.setNegativeButton(positiveText,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alertDialogBox = builder.create();
return alertDialogBox;
}
u can create custom dialog xml layout and call that xml layout in ur activity 您可以创建自定义对话框xml布局并在您的活动中调用该xml布局
dialog = new Dialog(activity.this);
dialog.setContentView(R.layout.yourcustomlayout);
dialog.getWindow().setBackgroundDrawable(
new ColorDrawable(android.graphics.Color.TRANSPARENT));
textview= (TextView) dialog.findViewById(R.id.textview_id);
dialog.show();
try this 尝试这个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.