How to add imageview on right hand side of action bar?

后端 未结 5 1870
星月不相逢
星月不相逢 2021-01-30 05:53

I want to add image view on action bar right hand side.I tried to do that but i couldn\'t. Can anyone help me?

This is my image view xml

 

        
5条回答
  •  [愿得一人]
    2021-01-30 06:00

    try this...

        ActionBar actionBar = getActionBar();
        actionBar.setDisplayOptions(actionBar.getDisplayOptions()
                | ActionBar.DISPLAY_SHOW_CUSTOM);
        ImageView imageView = new ImageView(actionBar.getThemedContext());
        imageView.setScaleType(ImageView.ScaleType.CENTER);
        imageView.setImageResource(R.drawable.adnace_search_i);
        ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(
                ActionBar.LayoutParams.WRAP_CONTENT,
                ActionBar.LayoutParams.WRAP_CONTENT, Gravity.RIGHT
                        | Gravity.CENTER_VERTICAL);
        layoutParams.rightMargin = 40;
        imageView.setLayoutParams(layoutParams);
        actionBar.setCustomView(imageView);
    

提交回复
热议问题