提问人:Telember 提问时间:1/8/2015 最后编辑:Telember 更新时间:7/7/2015 访问量:4293
如何在操作栏android中设置背景图像[已关闭]
How to set background image in actionbar android [closed]
问:
我是一名新的 Android 开发人员。如何在操作栏android中设置背景图像。
我可以在我的操作栏中添加图像背景。但无法缩放我的形象。
我的风格
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
</style>
主要活动
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(mCustomView);
}
custom_actionbar布局
<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/image" />
</RelativeLayout>
解决 方案
我在Android-ObservableScrollView>>使用此库
答:
3赞
Santhi Bharath
1/8/2015
#1
请阅读这篇文章: http://cyrilmottier.com/2013/05/24/pushing-the-actionbar-to-the-next-level/
在那里,您将找到有关您的任务的示例和教程
您也可以像这样设置操作栏背景。
private void setActionBar() {
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setCustomView(R.layout.header_actionbar);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.actionbar_blue)));
TextView tvHeader = (TextView) findViewById(R.id.tv_title_header_actionbar);
TextView tvSubheader = (TextView) findViewById(R.id.tv_subtitle_header_actionbar);
tvSubheader.setVisibility(View.GONE);
}
调用您的 .setActionBar()
oncreate()
评论