Detecting action bar icon long press

只愿长相守 提交于 2020-01-03 03:18:10

问题


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


回答1:


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);



回答2:


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



来源:https://stackoverflow.com/questions/18146082/detecting-action-bar-icon-long-press

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!