答案 0 :(得分:0)
使用Fragment是最好的方法。 http://developer.android.com/reference/android/support/v4/app/DialogFragment.html
你也可以使用Framelayout。 它很容易做一些定制。
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.zhangjunyi.testfornet.MainActivity"> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> //your activity layout </FrameLayout> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone"> //your dialog view, may do some custome //may use some animation to show, when the animation end > > //set the view visible, use a transparent background for // the view make //it looks like a dialog. </FrameLayout> </FrameLayout>
答案 1 :(得分:0)
您可以使用对话框视图在同一活动中添加UI并对其执行任务。在这里,您必须根据需要使用UI设置布局。
public void showDialog( Context context ) {
Dialog mDialog;
mDialog = new Dialog(context);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.setContentView(R.layout.layout_dialog);
mDialog.setCancelable(false);
mDialog.show();
RatingBar ratingBar = (RatingBar) mDialog.findViewById(R.id.dlg_rating_bar_);
TextView tvMessage = (TextView) mDialog.findViewById(R.id.dlg_tv_message);
EditText etComment = (EditText) mDialog.findViewById(R.id.dlg_et_comment);
Button btnAdd = (Button) mDialog.findViewById(R.id.dlg_btn_add);
Button btnDiscard = (Button) mDialog.findViewById(R.id.dlg_btn_discard);
// do your stuff here
}