How do I capture the menu key when settouchable (true); setfocusable (true) is set in popupwindow?

Source: Internet
Author: User
If the focus is set, the pop-up form is the current operation window. If you want the following activity response button, you need to register the keyboard event on the popupwindow, then, call the activity component to respond to the corresponding event. However, popupwindow seems to have only one ondismiss listener. How can I register a keyboard event listener?

 

You can use setonkeylistener to listen to a view in popupwindow and capture Keyboard Events. There is a view in popupwindow. You can use this view to add a keyboard event and set setonkeylistener to the view on the outermost layer.

For example
Menuview. setbackgrounddrawable (New bitmapdrawable ());
Menuview. setfocusable (true );
Menuview. setfocusableintouchmode (true );
Menuview. setonkeylistener (New onkeylistener ()
{

@ Override
Public Boolean onkey (view V, int keycode, keyevent event)
{
// Todo auto-generated method stub
If (event. getaction () = keyevent. keycode_menu)
{
Log. V ("keycode", "/" + keycode );
Popupback. Dismiss ();
Popupwindow. Dismiss ();
Return false;

}

Return false;
}
});

 

 

Refer to this example to add the above method to implement the function of clicking the menu key to close the menu.

Http://blog.csdn.net/kkfdsa132/article/details/6403404

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.