我有窗口默认操作栏,其中想要添加高度和宽度为30x30的Imageview。我可以这样做,我正在尝试此代码,但无法看到Imageview。
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayOptions(actionBar.getDisplayOptions() | ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView imageView = new ImageView(actionBar.getThemedContext());
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setImageResource(R.drawable.amazon);
ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(30, 30, Gravity.RIGHT | Gravity.CENTER_VERTICAL);
layoutParams.rightMargin = 40;
imageView.setLayoutParams(layoutParams);
actionBar.setCustomView(imageView);
答案 0 :(得分:0)
替换
ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(30, 30, Gravity.RIGHT | Gravity.CENTER_VERTICAL);
带
ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(
ActionBar.LayoutParams.WRAP_CONTENT,
ActionBar.LayoutParams.WRAP_CONTENT, Gravity.RIGHT
| Gravity.CENTER_VERTICAL);