0
View customNav = LayoutInflater.from(this).inflate(R.layout.activity_custom_layout, null);     
actionBar.setCustomView(customNav); 
actionBar.setDisplayShowCustomEnabled(true); 
final Context context1 = this; 
ImageButton ibItem1 = (ImageButton) customNav.findViewById(R.id.refresh); 
ibItem1.setPadding(280, 0, 0, 0); 
ibItem1.setVisibility(View.INVISIBLE); 
ibItem1.setOnClickListener(new View.OnClickListener() 
{ @Override public void onClick(View view) { } });

我已将带有图像按钮的自定义视图添加到 android 操作栏,图像按钮大小很小,所以需要更改操作栏的大小以获得适当的图像大小?

4

2 回答 2

0

我不确定您是否可以更改操作栏的大小,但您当然可以使用

showAsAction="ifRoom"

在项目标签中,使项目直接出现在操作栏中。如果没有足够的空间,该项目将显示在动作溢出中。

于 2013-11-12T07:11:11.337 回答
0

您可以动态更改操作栏的宽度和高度...

试试这个样本...

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    View contentView = getLayoutInflater().inflate(R.layout.test_layout, null);
    setContentView(contentView);
    LinearLayout layout = (LinearLayout) contentView.getParent()
            .getParent();
    View view = layout.getChildAt(0);
    ViewGroup actionBarView = (ViewGroup) view;
    LinearLayout.LayoutParams layoutParams = (android.widget.LinearLayout.LayoutParams) actionBarView
            .getLayoutParams();
    layoutParams.width = 200;
    layoutParams.gravity = Gravity.CENTER;
    actionBarView.setLayoutParams(layoutParams);
}
于 2013-11-12T07:11:42.943 回答