基本上,我希望有一個彈出框出現,以便用戶可以填寫表單而不是轉到下一頁。如何將佈局文件添加到Android活動頁面的一半
我不知道怎麼做,但我已經包括了什麼,我想
它我如何讓像我的xml文件到該活動
感謝
圖片基本上,我希望有一個彈出框出現,以便用戶可以填寫表單而不是轉到下一頁。如何將佈局文件添加到Android活動頁面的一半
我不知道怎麼做,但我已經包括了什麼,我想
它我如何讓像我的xml文件到該活動
感謝
圖片使用片段是最好的方法。 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>
您可以使用對話視圖來添加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
}
如何設置它,使其只顯示5顆星?我目前遇到了一些困難 –
檢查這個鏈接,你會得到解決你的問題。 http://www.mkyong.com/android/android-rating-bar-example/ –
不使用彈出對話框,而不是使用活動 –
更容易與[AlertDialog.Builder(http://developer.android.com/reference/android/app/AlertDialog.Builder.html),它可以你想要的樣式(通常的對話框也是) – snachmsm
我試圖儘可能偏離'AlertDialog.Builder',有沒有其他的方式做到這一點? –