I am trying to set Image into action bar, I am using CircularImagView to do that.
(ScaleType.FIT_END does not work for CircularImageView but i have also tried ImageView Same result even when ScaleType.FIT_END is applied).
It works fine for a larger screen phone but the title disappears for a less wide phone.
for example title shows fine for a wide phone like nexas 5x
But does not show up in a narrow device like my physical phone.
here is the code i am using to set the image
try {
// setting the image in the actionbar
getSupportActionBar().setDisplayOptions(getSupportActionBar().getDisplayOptions()
| ActionBar.DISPLAY_SHOW_CUSTOM);
CircleImageView imageView = new CircleImageView(getSupportActionBar().getThemedContext());
//imageView.setScaleType(CircleImageView.ScaleType.FIT_END);
//imageView.setForegroundGravity(Gravity.RIGHT);
imageView.setImageBitmap(bitmap);
getSupportActionBar().setCustomView(imageView);
// setting the image in actionbar ends here
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
Even the ScaleType.FIT_END or Gravity.RIGHT does not help
(ScaleType.FIT_END does not work for CircularImageView but i have also tried ImageView Same result even when ScaleType.FIT_END is applied).
bitmap is global variable and i am setting it in onCreate, to make things less complicated i didn't included that.
What might be the solution for this ?
By the suggestion of Manohar Reddy I have Created a LinearLayout to create a LayoutParam, have set width and height on that and have set that layout param to the imageview which fixed the issue
try {
// setting the image in the actionbar
getSupportActionBar().setDisplayOptions(getSupportActionBar().getDisplayOptions()
| ActionBar.DISPLAY_SHOW_CUSTOM);
CircleImageView imageView = new CircleImageView(getSupportActionBar().getThemedContext());
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(70, 70);
imageView.setLayoutParams(layoutParams);
imageView.setImageBitmap(bitmap);
getSupportActionBar().setCustomView(imageView);
// setting the image in actionbar ends here
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
had to create a new layout param cause there no imageview in activity xml so can't get the params. Hope this helps someone.