Android ActionBar options long click event

前端 未结 6 1132
南方客
南方客 2020-12-18 08:53

Android Can anyone know about Actionbar item options long click , I want to show text on LongClick on actionbar menu option like a hint on long press of actionBar long pres

6条回答
  •  醉话见心
    2020-12-18 09:22

    This is the code of function that works with me thanks to @YeeKhin change "main" to your menu name and "action_refresh" to your action name and "Activity" to your activity name

    public boolean onCreateOptionsMenu(Menu menu) {
    
            getMenuInflater().inflate(R.menu.main, menu);
    
            new Handler().post(new Runnable() {
                @Override
                public void run() {
                    final View v = findViewById(R.id.action_refresh);
    
                    if (v != null) {
                        v.setOnLongClickListener(new View.OnLongClickListener() {
                            @Override
                            public boolean onLongClick(View v) {
                                Toast.makeText(Activity.this,"Long Press!!",Toast.LENGTH_LONG).show();
                                return false;
                            }
                        });
                    }
                }
            });
    
            return true;
        }
    

提交回复
热议问题