最佳答案
我刚把我的代码库更新到棒棒糖上了我在动作条上有点问题。我正在使用 AppCompat 和 ActionBarActivity,并扩展自定义视图。似乎自定义视图不再占据整个屏幕的宽度,在左边留下一个细条
就像以前一样
现在看起来是这样
这是我用来设置动作条的代码,有人有什么想法吗?
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();
}
});
}
剪辑
取出自定义视图并改变背景现在占用了整个宽度。所以问题是,我们如何让 CustomView 占据 ActionBar 的整个宽度?