我在对话框的右上角显示有箭头形状的自定义对话框的要求。我谷歌退出为,结果我得到了相同的,但是,它的弹出窗口不是DIALOG。自定义对话框与三角对话境外在右上角
因为,我有对话框打开时禁用背后对话框的背景下,弹出窗口是不是在这种情况下使用。雅,我可以禁用与弹出窗口背景触摸也。但是,我认为对话是更好的解决方案。
我在我的屏幕上的特定位置成功地打开对话框,现在,我只需要设置对话框中的箭头(在右上角的三角形)。
我怎样才能实现这一目标?
谢谢。
我在对话框的右上角显示有箭头形状的自定义对话框的要求。我谷歌退出为,结果我得到了相同的,但是,它的弹出窗口不是DIALOG。自定义对话框与三角对话境外在右上角
因为,我有对话框打开时禁用背后对话框的背景下,弹出窗口是不是在这种情况下使用。雅,我可以禁用与弹出窗口背景触摸也。但是,我认为对话是更好的解决方案。
我在我的屏幕上的特定位置成功地打开对话框,现在,我只需要设置对话框中的箭头(在右上角的三角形)。
我怎样才能实现这一目标?
谢谢。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/dialogbox"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/your_image_arrow" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="16dp"
android:text="Do you want to logout"
android:textSize="15dp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/customDialogCancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/customDialogOk"
android:layout_toStartOf="@+id/customDialogOk"
android:layout_weight="1"
android:background="@drawable/buttonview"
android:text="Cancel"
android:textAlignment="center"
android:textColor="#00bfff"
android:textStyle="bold" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@android:color/darker_gray" />
<Button
android:id="@+id/customDialogOk"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:background="@drawable/buttonview"
android:text="Logout"
android:textAlignment="center"
android:textColor="#00bfff"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
,并在你的活动这样做:
final Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.custom_dialog);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
// Custom Android Allert Dialog Title
Button dialogButtonCancel = (Button) dialog.findViewById(R.id.customDialogCancel);
Button dialogButtonOk = (Button) dialog.findViewById(R.id.customDialogOk);
// Click cancel to dismiss android custom dialog box
dialogButtonCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
// Your android custom dialog ok action
// Action for custom dialog ok button click
dialogButtonOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(CategoryActivity.this,
LoginActivity.class);
startActivity(intent);
finish();
}
});
dialog.show();
}
});
我的对话框有取消和注销按钮。你可以编写你自己的功能。希望这会有所帮助。
这里使用我创建了一个自定义对话框,让你。根据你改变形象: 创建dialog.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:layout_gravity="end"
/>
</LinearLayout>
现在从您的活动
View view = getLayoutInflater().inflate(R.layout.dialog,null);
final AlertDialog myDialog = new AlertDialog.Builder(TestActivity.this)
.setView(view)
.create();
infoDialog.show();
Window window = myDialog.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
//change the value of x and y to change the position of dialog box on the screen
wlp.x = 100;
wlp.y = 100;
wlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(wlp);
ya谢谢,正在尝试.. –
您好先生,这个三角形应该在对话框的顶部边框的外侧.. –
在您想要显示对话框并通过更改位置来更改位置的活动中使用此代码wlp.x和wlp.y值 – sumit
试图..感谢.. –
你好先生创建对话框,这个三角形应该出侧Dialog的顶部边框.. –