Antwan
Antwan

Reputation: 3876

Android - custom view in action bar not clickable

I have an ActionBar which has a home button and one menu item and in the middle a custom view which is a LinearLayout containing an ImageView and two TextView but I can't make it clickable i tried many solution with no success
even I added clickable attribute on the layout and the image and textview.

 android:clickable="true"

and this is my code

actionbar.setCustomView(R.layout.alias);
         View v=getLayoutInflater().inflate(R.layout.alias,null);
         ImageView imageView=(ImageView) v.findViewById(R.id.profile_pic);
         imageView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(getApplicationContext(),"test",Toast.LENGTH_LONG).show();
                Log.d("fff","rrr");
            }
        });

Upvotes: 0

Views: 815

Answers (1)

Yash Sampat
Yash Sampat

Reputation: 30601

Replace

View v=getLayoutInflater().inflate(R.layout.alias,null);

with

View v = actionbar.getCustomView();

Try this. This should work.

Upvotes: 2

Related Questions