Javascript 点击菜单按钮后的确认消息是否在onClick事件或XML中完成?

Javascript 点击菜单按钮后的确认消息是否在onClick事件或XML中完成?,javascript,android,jquery,xml,Javascript,Android,Jquery,Xml,如果我在寻找点击菜单项按钮后出现的灰色确认栏(几秒钟后消失),它会在MainActivity.java中的onClick事件中完成吗?还是在XML中完成?奇怪的是,消息出现在我实现OnClick事件之前。我猜它将在onClick中完成,但我不知道您将使用什么来显示它(或确切的语法) public void confirmPart(菜单项){ 字符串消息=当前消息; (我需要什么代码才能在几秒钟后显示和消失通知栏) }首先,您必须创建一个菜单项,因为您的问题中有一个菜单项。在res->menu中

如果我在寻找点击菜单项按钮后出现的灰色确认栏(几秒钟后消失),它会在MainActivity.java中的onClick事件中完成吗?还是在XML中完成?奇怪的是,消息出现在我实现OnClick事件之前。我猜它将在onClick中完成,但我不知道您将使用什么来显示它(或确切的语法)

public void confirmPart(菜单项){
字符串消息=当前消息;
(我需要什么代码才能在几秒钟后显示和消失通知栏)

}

首先,您必须创建一个菜单项,因为您的问题中有一个菜单项。在
res->menu
中创建此xml文件。命名文件
main.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    <!--Change the below with your package name-->
    tools:context="com.example.mytest.MainActivity" >

    <item
        android:id="@+id/action_confirm"
        android:onClick="confirmPart"
        android:title="@string/action_confirm"
        app:showAsAction="withText|ifRoom"/>

</menu>

确认栏是什么意思?你是说祝酒词吗?是的,我的意思是祝酒词!谢谢
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        // Here ensure that xml file name main.xml is found under the res->menu folder
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_confirm) {
            //Here is where you define what happens when the menu item is clicked
            //For example I have added a Toast message
            Toast.makeText(getApplicationContext(), "The message you want to display", Toast.LENGTH_LONG).show();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }