不废话,先爆照
<RelativeLayout 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" tools:context=".HomeActivity" > <RelativeLayout android:id="@+id/rl_search_background" android:layout_width="match_parent" android:layout_height="wrap_content" android:focusable="true" android:focusableInTouchMode="true" android:paddingTop="4dp" android:paddingBottom="4dp" android:paddingLeft="8dp" android:paddingRight="8dp"> <RelativeLayout android:id="@+id/bt_nearby_search_background" android:layout_width="match_parent" android:layout_height="30dp" android:layout_centerInParent="true" android:background="@drawable/bg_search" android:padding="4dp" android:gravity="center"> <Button android:id="@+id/btn_search_icon_background" android:layout_width="16dp" android:layout_height="16dp" android:layout_centerVertical="true" android:background="@mipmap/icon_search" android:clickable="false" /> <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/btn_search_icon_background" android:layout_centerVertical="true" android:layout_marginLeft="8dp" android:background="@null" android:textSize="12sp" android:hint="@string/search_hint"/> </RelativeLayout> </RelativeLayout> </RelativeLayout>design如下
/** * 点击评分,如果评分后,显示的弹出框 */ private void makePopupWindows() { View view = LayoutInflater.from(HomeActivity.this).inflate( R.layout.background, null); mPopupWindow = new PopupWindow(view, mScreenWidth, 600); WindowManager.LayoutParams params = getWindow().getAttributes(); params.alpha = 0.5f; getWindow().setAttributes(params); mPopupWindow.setOutsideTouchable(true); mPopupWindow.setFocusable(true); // 设置PopupWindow可获得焦点 mPopupWindow.setTouchable(true); // 设置PopupWindow可触摸 mPopupWindow.showAsDropDown(background_button); }
mPopupWindow.setOutsideTouchable(true); mPopupWindow.setFocusable(true); // 设置PopupWindow可获得焦点 mPopupWindow.setTouchable(true); // 设置PopupWindow可触摸
style name="anim_menu_bottombar"> <item name="android:windowEnterAnimation">@anim/menu_bottombar_in</item> <item name="android:windowExitAnimation">@anim/menu_bottombar_out</item> </style>在工程res下新建anim文件夹,在anim文件夹先新建两个xml文件
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="250" android:fromYDelta="100.0%" android:toYDelta="0.0" /> </set>menu_bottombar_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="250" android:fromYDelta="0.0" android:toYDelta="100%" /> </set>
mPopupWindow.setAnimationStyle(R.style.menu_anim_bottombar);
/** * 点击评分,如果评分后,显示的弹出框 */ private void makePopupWindows() { View view = LayoutInflater.from(HomeActivity.this).inflate( R.layout.background, null); mPopupWindow = new PopupWindow(view, mScreenWidth, 600); WindowManager.LayoutParams params = getWindow().getAttributes(); params.alpha = 0.5f; getWindow().setAttributes(params); mPopupWindow.setOutsideTouchable(true); mPopupWindow.setFocusable(true); // 设置PopupWindow可获得焦点 mPopupWindow.setTouchable(true); // 设置PopupWindow可触摸 mPopupWindow.showAsDropDown(background_button); view.setFocusableInTouchMode(true); mPopupWindow.setBackgroundDrawable(new BitmapDrawable()); view.setOnKeyListener(new android.view.View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // TODO Auto-generated method stub if (keyCode == KeyEvent.KEYCODE_BACK &&mPopupWindow.isShowing()) { mPopupWindow.dismiss(); WindowManager.LayoutParams params= getWindow().getAttributes(); params.alpha=1.0f; getWindow().setAttributes(params); return true; } return false; } }); }