Android action bar menu item with actionLayout not working properly

后端 未结 4 983
野趣味
野趣味 2021-02-05 03:19

Hi I am developing an Android application. In my application I am using Sherlock action. I\'ve defined few menu items in action-bar like in following manner

<         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-05 04:08

    Full working code

     
    

    Code:

    @Override
    public boolean onCreateOptionsMenu(final Menu menu) {
        getMenuInflater().inflate(R.menu.menu,menu); MenuItem item = menu.findItem(R.id.mSearch);
        ImageView iv= (ImageView) item.getActionView().findViewById(R.id.search_1);
        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(context, "clicked", Toast.LENGTH_SHORT).show();
            }
        });
        return true;
    }
    

提交回复
热议问题