How to set background image in actionbar android [closed]

余生颓废 提交于 2019-12-14 04:23:45

问题


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.

My style

<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 layout

<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>

Solutions

I use this Lib >> Android-ObservableScrollView


回答1:


Please read this article: http://cyrilmottier.com/2013/05/24/pushing-the-actionbar-to-the-next-level/

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

call setActionBar() in your oncreate().



来源:https://stackoverflow.com/questions/27834846/how-to-set-background-image-in-actionbar-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!