美文网首页
ActionBar设置Title 居中

ActionBar设置Title 居中

作者: mengyong | 来源:发表于2017-11-03 17:31 被阅读0次

getActionBar().setBackgroundDrawable(new ColorDrawable(0xff33bb77));

// 返回箭头(默认不显示)

getActionBar().setDisplayHomeAsUpEnabled(true);

// 左侧图标点击事件使能

getActionBar().setHomeButtonEnabled(true);

// 使左上角图标(系统)是否显示

getActionBar().setDisplayShowHomeEnabled(false);

// 显示标题

getActionBar().setDisplayShowTitleEnabled(false);

//显示自定义视图

getActionBar().setDisplayShowCustomEnabled(true);

TextView textView = new TextView(this);

textView.setText($title);

textView.setTextSize(15);

textView.setTextColor(0xffffffff);

LinearLayout actionbarLayout = new LinearLayout(this);

getActionBar().setCustomView(actionbarLayout,new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,

ActionBar.LayoutParams.WRAP_CONTENT));

ActionBar.LayoutParams mP = (ActionBar.LayoutParams) actionbarLayout

.getLayoutParams();

mP.gravity = mP.gravity & ~Gravity.HORIZONTAL_GRAVITY_MASK| Gravity.CENTER_HORIZONTAL;

actionbarLayout.addView(textView);

getActionBar().setCustomView(actionbarLayout, mP);

相关文章

网友评论

      本文标题:ActionBar设置Title 居中

      本文链接:https://www.haomeiwen.com/subject/bjatmxtx.html