您的位置:首页 > 其它

Actionbar

2016-03-14 15:58 441 查看
01)在java代码中加载布局来设置
import android.app.ActionBar;
import android.app.ActionBar.LayoutParams;
private void initActionBar() {
ActionBar actionBar = getActionBar();
        if(mActionBar != null){
            ViewGroup v = (ViewGroup)LayoutInflater.from(this).inflate(R.layout.list_actionbar, null);
            ActionBar.LayoutParams lp = new ActionBar.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            mActionBar.setDisplayShowTitleEnabled(false);
            mActionBar.setDisplayShowHomeEnabled(false);
            mActionBar.setDisplayShowCustomEnabled(true);
            mActionBar.setCustomView(v, lp);
            
            ImageView headerBackBtn = (ImageView)v.findViewById(R.id.header_back);
            headerBackBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onBackPressed();
                }
            });
        }
}
02)在onCreate()方法中调用该方法,并传入自定义的布局文件ID:
@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_diy_action_bar);

// 自定义actionbar的布局
initActionBar();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: