Use of Dialog,toast,optionmenu,contextmenu in Android

Source: Internet
Author: User

These interfaces are interface elements that are often used in development beyond the main interface of the activity,

The Dialog,toast interface can be customized. The interface of Optionmenu and ContextMenu can also be customized, but not dialog so flexible, it can only customize some title,item and the like.

1.dialog Custom Interface

Alertdialog dialog=new Alertdialog.builder (mainactivity.this). Create ();
Dialog.setview (view);

2.toast Custom Interface

Toast toast= Toast.maketext (mainactivity.this, "abc", Toast.length_long);
Toast.setview (New Button (Mainactivity.this));
Toast.show ();

3.optionmenu

How to use

public boolean Oncreateoptionsmenu (menu menu) This function is called only once, and it can be considered a part of the activity life cycle.

public boolean Onprepareoptionsmenu (menu menu) This function is called before the menu is displayed.

public boolean onoptionsitemselected (MenuItem item) is invoked when it chooses to touch an item

4.contextmenu

ContextMenu need registe to use, register to which view, and then long press the view, the framework will callback oncreatecontextmenu this function

This.registerforcontextmenu (TXT2);

ContextMenu is called again before each display Oncreatecontextmenu

public void Oncreatecontextmenu (ContextMenu menu, View v,contextmenuinfo menuinfo)//will be called before each display

public boolean oncontextitemselected (MenuItem Item)

Use of Dialog,toast,optionmenu,contextmenu in Android

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.