Android Popup Window Example, Custom popup window, adapter popup window, code popup window, example popup window, github popup window.
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/rl" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="16dp" tools:context=".MainActivity" android:background="#f5f1e0" >layout/ custom_popup.xml
<Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Show Popup Window" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rl_custom_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="2dp" android:background="#ab2fc4" >class PopupWindow.java.
<ImageButton android:id="@+id/ib_close" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_setting_press" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:background="@null" />
<TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is a sample popup window." android:layout_centerInParent="true" android:padding="25sp" />
</RelativeLayout>
public class PopupWindown extends Activity {
private Context mContext;
private Activity mActivity;
private RelativeLayout mRelativeLayout;
private Button mButton;
private PopupWindow mPopupWindow;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.acitivyt_popup);
}
private void init(){
// Get the application context mContext = getApplicationContext();
// Get the activity mActivity = PopupWindown.this;
// Get the widgets reference from XML layout mRelativeLayout = (RelativeLayout) findViewById(R.id.rl);
mButton = (Button) findViewById(R.id.btn);
// Set a click listener for the text view mButton.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
// Initialize a new instance of LayoutInflater service LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
// Inflate the custom layout/view View customView = inflater.inflate(R.layout.custom_layout,null);
// Initialize a new instance of popup window mPopupWindow = new PopupWindow(
customView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT );
// Set an elevation value for popup window // Call requires API level 21 if(Build.VERSION.SDK_INT>=21){
mPopupWindow.setElevation(5.0f);
}
// Get a reference for the custom view close button ImageButton closeButton = (ImageButton) customView.findViewById(R.id.ib_close);
// Set a click listener for the popup window close button closeButton.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
// Dismiss the popup window mPopupWindow.dismiss();
}
});
mPopupWindow.showAtLocation(mRelativeLayout, Gravity.CENTER,0,0);
}
});
}
}
ConversionConversion EmoticonEmoticon