Android ActionBarSherlock Custom View

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

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

Now it contains an image button with the resource id R.id.back. How can I handle the onclick listener of this element.

Yours faithfully,

+4
source share
1 answer

You can also inflate your performance if you get an inflatable layout and search for a button and then attach a click listener.

So, for example, something like these lines if your button had the identifier "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); 
+12
source

Source: https://habr.com/ru/post/1434358/


All Articles