Android popupwindow example

Android-popupwindow-example-featured.png

Example of utilizing PopupWindow

 Android popupwindow example

android.widget.PopupWindow may be used to display a random view. The popup home windows is really a floating container that seems on the top from the current activity.

Example of PopupWindow

Create /res/layout/popup.xml to define viewing PopupWindow.


android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:orientation=”vertical”
android:background=”@android:color/background_light”>
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:orientation=”vertical”
android:layout_margin=”1dp”
android:background=”@android:color/more dark_grey”>
>
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:orientation=”vertical”
android:layout_margin=”20dp”>
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”It is a PopupWindow” />
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:src=”" />
android:id=”@+id/dismiss”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”Dismiss” />


Primary activity Java code to handle PopupWindow

package com.exercise.AndroidPopupWindow

import android.application.Activity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup.LayoutParams
import android.widget.Button
import android.widget.PopupWindow

public class AndroidPopupWindowActivity stretches Activity Known as once the activity is first produced. */
@Override
public void onCreate(Bundle savedInstanceState) primary)

final Button btnOpenPopup = (Button)findViewById(R.id.openpopup)
btnOpenPopup.setOnClickListener(new Button.OnClickListener()produced method stub
popupWindow.dismiss()
)

popupWindow.showAsDropDown(btnOpenPopup, 50, -30)

)

primary.xml


android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:orientation=”vertical” >

android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”@string/hello” />
android:id=”@+id/openpopup”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”Open Popup Window” />

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)