i leaf
i leaf

Reputation: 273

android create a popup screen for showing help on a page that extends view

I am creating an application which using custom view and i have designed the layout using a class that extends view.

Now i have a help icon on that view which have to popup on click.I have tried dialog window but i need a window without title and border.

I have checked some games and they are using what exactly i need. Anybody can suggest a better solution?

here is my sample code to get help button

public boolean onTouchEvent(MotionEvent me) {
        int action = me.getAction();
        if(action == MotionEvent.ACTION_DOWN ){
            x = me.getX();
            y = me.getY();
if (x >= helpButtonX && x < (helpButtonX +help.getWidth())&&
 y >= helpButtonY && y <     helpButtonY + help.getHeight() ) 
  {
           // code toshow popup
   }
  }
}

Upvotes: 0

Views: 2784

Answers (3)

Kashif Siddiqui
Kashif Siddiqui

Reputation: 1546

You can just use a PopupWindow with custom layout.

Add this code in your {//Code to show popup}

//Get a layout inflator
LayoutInflater li = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
//Initialize a popup window with custom xml view - R.layout.popup.xml
View popupView = li.inflate(R.layout.popup, null);
final PopupWindow pW = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

To dismiss it use pW.dismiss() wherever you want

Try this: http://android-er.blogspot.jp/2012/03/example-of-using-popupwindow.html

Upvotes: 0

ASceresini
ASceresini

Reputation: 419

You can create a hidden View that is set using relativeLayout over the other elements in the layout.xml. when the user clicks the help button, the visibility is changed to visible and the View is shown. YOu can then set an onclick listener on the View that when they touch it, it will be hidden again.

Upvotes: 1

Paresh Mayani
Paresh Mayani

Reputation: 128428

Yes you can create a custom dialog with the layout designed by you.

For that simply create a dialog and set the layout by using setContentView() method.

For example:

 Dialog dialog = new Dialog(myActivity.this);
 dialog.setContentView(R.layout.myDialogLayout);
 dialog.setTitle("");
 dialog.setCancelable(true);
 dialog.show();

Upvotes: 1

Related Questions