在Android中,是否可以在现有的Support ActionBar上绘制一些视图,例如ImageViews?
答案 0 :(得分:1)
试试这个样本......
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
ImageView imageView = new ImageView(actionBar.getThemedContext());
ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(
ActionBar.LayoutParams.WRAP_CONTENT,
ActionBar.LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
imageView.setLayoutParams(layoutParams);
imageView.setImageResource(R.drawable.image1);
imageView.setScaleType(ImageView.ScaleType.CENTER);
actionBar.setCustomView(imageView);