android - 在全屏对话框顶部显示片段(alertDialog)
问题描述
我有一个全屏透明警报对话框,它在中心底部显示一些图标,高度和宽度为 match_parent,现在我需要在此警报对话框顶部显示一个片段。
我尝试过以下事情:
创建了另一个警报对话框,该对话框有效但与 android 普通片段有关
尝试设置翻译 z ,提升到片段容器但没有运气
尝试下面的代码但不工作
View view = findViewById(R.id.frag_container); ((View)view.getParent()).requestLayout(); view.bringToFront(); view.invalidate();
现在的问题是
- 这是可以实现的
- 如果是,那么怎么样?
解决方案
试试这个代码:
public class DialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setPositiveButton(R.string.fire, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
toast.makeText(this,"enter a text here",Toast.LENTH_SHORT).show();
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
});
// Create the AlertDialog object and return it
return builder.create();
}
}
}
点击此链接了解更多详情 - https://www.tutorialspoint.com/android/android_alert_dialoges.htm