如何在ActionBar Android中设置背景图片 [英] How to set background image in actionbar android

查看:425
本文介绍了如何在ActionBar Android中设置背景图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名新的Android开发人员.如何在Actionbar Android中设置背景图片.

I'm a new Android developer. How to setting background image in actionbar android.

我可以在操作栏中添加图像背景.但无法缩放我的图像.

I can add image background within my actionbar. but cant scaling my image.

我的风格

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

</style>

MainActivity

 @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

推荐答案

请阅读这篇文章:您将找到有关您的问题的示例和教程

There you will find example and tutorial about your questuion

您还可以像这样设置操作栏背景.

And also you can set action bar background like this.

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);
    }

在您的oncreate()中呼叫setActionBar().

这篇关于如何在ActionBar Android中设置背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆