popWindows設定背景色及相應的佈局
阿新 • • 發佈:2019-01-26
private LayoutInflater layoutInflater; private PopupWindow popupAvatarWindow; private void showAvatarPopupWindow() { if (layoutInflater == null) { layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); } View popView = layoutInflater.inflate( R.layout.popwindow_photograph_album, null); //拍照 TextView takePicturesTv = (TextView) popView.findViewById(R.id.take_pictures_avatar); takePicturesTv.setOnClickListener(this); //從相簿中選擇 TextView chooseAlbumTv = (TextView) popView.findViewById(R.id.upload_album_avatar); chooseAlbumTv.setOnClickListener(this); //取消 TextView cancalOperateTv = (TextView) popView.findViewById(R.id.cancal_operate); cancalOperateTv.setOnClickListener(this); //LinearLayout WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT if (popupAvatarWindow == null) { popupAvatarWindow = new PopupWindow(popView, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); } popupAvatarWindow.setFocusable(true); popupAvatarWindow.setOutsideTouchable(true); //設定背景 popupAvatarWindow.setBackgroundDrawable(getResources().getDrawable(R.color.gray_b0000000)); popupAvatarWindow.showAtLocation(personalSettingsLayout, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
}
<!-- popwindow_photograph_album -->
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!-- android:layout_marginLeft="60dp" android:layout_marginRight="60dp" --> <LinearLayout android:id="@+id/cancel_layout" android:layout_width="match_parent" android:layout_height="44dp" android:layout_alignParentBottom="true" android:layout_marginLeft="60dp" android:layout_marginRight="60dp" android:layout_marginTop="10dp" android:background="@drawable/round_white_bg" android:orientation="vertical"> <TextView android:id="@+id/cancal_operate" style="@style/dialog_textview_size16_dark544646" android:layout_width="match_parent" android:layout_height="44dp" android:layout_gravity="center" android:gravity="center" android:text="取消" /> </LinearLayout> <LinearLayout android:id="@+id/phote_album_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@+id/cancel_layout" android:layout_marginLeft="60dp" android:layout_marginRight="60dp" android:background="@drawable/round_white_bg" android:orientation="vertical"> <TextView android:id="@+id/take_pictures_avatar" style="@style/dialog_textview_size16_blue07b2f7" android:layout_width="match_parent" android:layout_height="44dp" android:layout_gravity="center" android:gravity="center" android:text="拍照" /> <View android:layout_width="match_parent" android:layout_height="1px" android:background="@color/CCCCCC" /> <TextView android:id="@+id/upload_album_avatar" style="@style/dialog_textview_size16_blue07b2f7" android:layout_width="match_parent" android:layout_height="44dp" android:layout_gravity="center" android:gravity="center" android:text="從相簿上傳" /> </LinearLayout> </RelativeLayout>