Android - 将视图绘制到SupportActionBar上

时间:2013-12-18 04:36:18

标签: android view overlay android-actionbar-compat

在Android中,是否可以在现有的Support ActionBar上绘制一些视图,例如ImageViews?

1 个答案:

答案 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);