2

I want to detect long press on application's icon in the ActionBar in Android application. Is it possible?

Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335

2 Answers2

3

Unfortunately standard android tools doesn't provide such possibility.

The only possible way is to create your own actionLayout, see android:actionLayout

I think, this question is very similar to Android ActionBar options long click event

Community
  • 1
  • 1
OFFmind
  • 597
  • 1
  • 5
  • 13
2

Add custom view to action bar

    View view     = getLayoutInflater().inflate(R.layout.actionbar,null);
    btnClose    = (ImageView) view.findViewById(R.id.btnClose);
    btnClose.setOnLongClickListener(new OnLongClickListener()
    {

        @Override
        public boolean onLongClick(View v) {
            Log.d("rvg", "Long click:");
            return false;
        }
    });



  getSupportActionBar() . setCustomView(view);
RVG
  • 3,538
  • 4
  • 37
  • 64