Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ActionBarSherlock Custom View

I have added a custom top bar to my ActionBarSherlock as in

getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setCustomView(R.layout.my_custom_view);

Now this contains an Image Button with the resource id of R.id.back. How do i handle the onclick listener of this item.

Kind Regards,

like image 745
AndroidDev Avatar asked Dec 15 '22 19:12

AndroidDev


1 Answers

You can also inflate your view if you get a layout inflater and search for the button and then attach a click listener.

So for example something along these lines if your button had id "myButton":

getSupportActionBar().setDisplayShowCustomEnabled(true);
View view = getLayoutInflater().inflate(R.layout.my_custom_view, null);
Button mybutton = (Button)view.findViewById(R.id.myButton);            
mybutton.setOnClickListener(new OnClickListener()
{
        @Override
        public void onClick(View v)
        {
        /** Your click actions here. */
        }
});
getSupportActionBar().setCustomView(view);
like image 59
Marco RS Avatar answered Jan 07 '23 23:01

Marco RS