所以,我刚刚将我的代码库更新为Lollipop,而且我遇到了Action Bar的问题.我正在使用AppCompat和ActionBarActivity,并为自定义视图充气.似乎自定义视图不再占据屏幕的整个宽度,在左侧留下一条细条
过去的样子
它看起来现在的样子
这是我用来设置Action Bar的代码.有人有主意吗?
final ActionBar actionBar = getSupportActionBar();
if(actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setCustomView(R.layout.action_bar_content_search_custom_view);
actionBar.setBackgroundDrawable(null);
// actionBar.setStackedBackgroundDrawable(null);
TextView title = (TextView) actionBar.getCustomView().findViewById(R.id.action_bar_title);
title.setText(R.string.youtube);
ImageView back = (ImageView) actionBar.getCustomView().findViewById(R.id.action_bar_back);
back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
Run Code Online (Sandbox Code Playgroud)
编辑
取出自定义视图并更改背景现在占用整个宽度.问题是,我们如何让CustomView占用ActionBar的整个宽度?
android android-appcompat android-actionbar android-5.0-lollipop