本文介绍了操作栏的Andr​​oid宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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) { } });

我添加自定义视图与图像按钮,机器人操作栏,图像按钮的大小
小,所以需要改变操作栏的大小进行适当的图像大小?

I have added custom view with image button to android action bar,image button size issmall,so need to change the size of action bar for proper image size?

推荐答案

您可以改变动作条的THW宽度和高度动态...

you can change thw width and height of the actionbar dynamically...

试试这个样本...

@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);
}

这篇关于操作栏的Andr​​oid宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 08:50