Detecting action bar icon long press

2019-06-06 09:14发布

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

2条回答
该账号已被封号
2楼-- · 2019-06-06 09:31

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

查看更多
Anthone
3楼-- · 2019-06-06 09:36

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);
查看更多
登录 后发表回答