Android ActionBar options long click event

前端 未结 6 1131
南方客
南方客 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:11

    Do you want to capture long press on menu item on action bar? As for me, after finding 2,3 hour, I found this solution. This is perfectly work for me.

          @Override
         public boolean onCreateOptionsMenu(final Menu menu) {
    
    
    
        getMenuInflater().inflate(R.menu.menu, menu);
    
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                final View v = findViewById(R.id.action_settings);
    
                if (v != null) {
                    v.setOnLongClickListener(new CustomLongOnClickListener());
                }
            }
        });
    
        return true;
    }
    

提交回复
热议问题