Android Meun usage

Click the menu entity key to pop up the menu : Here's the picture

main_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MenuTest"/>
</LinearLayout>

item_menu.xml( To be in rec Create a menu Folder , And then in menu Create this file under the folder )

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/main_menu_1" android:title=" newly added "></item>
<item android:id="@+id/main_menu_2" android:title=" modify "></item>
<item android:id="@+id/main_menu_3" android:title=" Delete "></item>
</menu>

MainActivity.java

package com.zy.viewpager;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast; /**
* Created by Administrator on 2016/11/19.
*/ public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu_view);
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
new MenuInflater(this).inflate(R.menu.item_menu,menu);
return true;
} @Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch (item.getItemId()){
case R.id.main_menu_1:
Toast.makeText(this," The user clicked " + item.getTitle(),Toast.LENGTH_SHORT).show();
break;
case R.id.main_menu_2:
Toast.makeText(this," The user clicked " + item.getTitle(),Toast.LENGTH_SHORT).show();
break;
case R.id.main_menu_3:
Toast.makeText(this," The user clicked " + item.getTitle(),Toast.LENGTH_SHORT).show();
break;
default:
Toast.makeText(this,"TEST",Toast.LENGTH_SHORT).show();
break;
}
return super.onMenuItemSelected(featureId,item);
}
}

The test results :

end !!

Android Meun More about usage

  1. Android ViewPager usage

    Android ViewPager usage scene : The first time you open an application , The program will have a prompt page to show the functions of the application : Or when the program is updated , What new features are being updated , You can use ViewPager Demo describe ...

  2. Android Intent A comprehensive summary of usage

    [ Code full screen view ]-Android Intent A comprehensive summary of usage // [1].[ Code ] Call the dialer Jump to [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] / ...

  3. Android GLSurfaceView Usage details ( Two )

    Input how to handle        If you develop an interactive application ( As the game ), You usually need to subclass GLSurfaceView, So you can get the input events . Here's an example : java Code : package eoe.ClearTes ...

  4. Android ScrollView usage

    Android ScrollView usage I tried to use it today Android The roller of , Here's a little test , Read the test file , Mainly used scrollTo Functions and getScrollY(), Program click BUTTON Button ...

  5. Android Service Explanation of usage knowledge points

    Android Service Study Service Related knowledge : android service Basic knowledge of , Life cycle ,service classification , Operating location ( The local service , Remote services ), Run type ( Front desk service , Background services ) ...

  6. Android Fragment Explanation of usage knowledge points

    Android Fragment Explanation of usage debris , It's there to better show UI The design of the , Make the program more fully displayed .Fragment Appearance , For example, wechat's main interface contains multiple Fragment, Make wechat function more concise and clear ...

  7. Android spannableStringBuilder Usage arrangement

    Android spannableStringBuilder Usage arrangement classification : Android Development 2013-11-29 10:58 5009 Human reading   Comment on (0)  Collection   report Androidspannabl ...

  8. Android Fragment Usage details (2)-- Dynamic addition Fragment

    In the last article <Android Fragment Usage details (1)-- Static use Fragment> We explained Fragment The simplest use of . Let's talk about it this time Fragment The usage of complex one lost lost . In the code ...

  9. Android.mk Usage arrangement

    [ Time :2016-05] [ state :Open] The output message because Android.mk The use of GNU Make The grammar of , It can be used conveniently .ndk The following three formats of message output are provided : error: debug print ...

Random recommendation

  1. nginx Static and dynamic separation configuration of (tomcat)

    nginx+tomcat It's a static and dynamic separation configuration First, in the nginx Added to the profile of tomcat Cluster configuration of upstream tomcats { ip_hash; server 192.168.0.251:8 ...

  2. Inter thread communication --wait and notify

    Use wait.notify Method to realize the communication between threads ( Note that both methods are object Methods of the class , let me put it another way java These two methods are provided for all objects ) 1.wait and notify Must cooperate synchronized Turn off ...

  3. Leetcode#106 Construct Binary Tree from Inorder and Postorder Traversal

    Original address Basic operation of binary tree [       ]O[              ] [       ][              ]O Code : TreeNode *restore(vector<i ...

  4. Common database driver class /URL/ Default port

    Common database driver class /URL/ Default port 1.Oracle:     Format :     drive :oracle.jdbc.driver.OracleDriver     URL:jdbc:oracle:thin ...

  5. HTML5 preliminary —— New form elements and properties

    HTML5 preliminary -- New form elements and properties HTML5 preliminary -- New form elements and properties <!DOCTYPE html> <html> <head> <meta chars ...

  6. Overload and Override The difference between .Overloaded Whether the method of can change the type of return value ?

    Method rewrite Overriding And overloading Overloading yes Java Different manifestations of polymorphism . rewrite Overriding It is a manifestation of polymorphism between parents and children , heavy load Overloading Is a manifestation of polymorphism in a class . Such as ...

  7. About AMD 、CMD、 commonjs The understanding of

    First of all, what is amd.cmd and commonjs. in general , These are the three things js Module specification of . however , What's the difference between the three .... amd Specifications are applied to browsers , Such as requireJS. commonjs Standardize applications and services ...

  8. One 、tars Brief introduction Two 、tars Installation and deployment information preparation

    1.github Address https://github.com/Tencent/Tars/ 2.tars yes RPC Development framework , At present, we support c++,java,nodejs,php 3.tars Tencent has already used fast ...

  9. web API brief introduction ( 3、 ... and ): The client stores Web Storage API

    summary Previous articles :web API brief introduction ( Two ): The client stores document.cookie API Client storage is similar to dynamic website in a way . Dynamic website uses server to store data , And client storage uses client to store data . W ...

  10. Discuz- Reading Rights

    Set the permission level for users to browse posts or attachments , Range 0-255,0 To prevent users from browsing any posts or attachments . When the user's reading permission is less than that of the post or attachment ( The default is 1) when , Users will not be able to read the post or download the attachment