如何在actionbar android中设置背景图像

如何在actionbar android中设置背景图像,android,android-actionbar,themes,android-appcompat,android-toolbar,Android,Android Actionbar,Themes,Android Appcompat,Android Toolbar,我是一个新的Android开发者。如何在actionbar android中设置背景图像 我可以在actionbar中添加图像背景。但是我不能缩放我的图像 我的风格 自定义操作栏布局 解决方案 我使用这个Lib>请阅读本文: 在那里你可以找到关于你的问题的例子和教程 你也可以像这样设置动作条的背景 private void setActionBar() { getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_S

我是一个新的Android开发者。如何在actionbar android中设置背景图像

我可以在actionbar中添加图像背景。但是我不能缩放我的图像

我的风格

自定义操作栏布局


解决方案


我使用这个Lib>

请阅读本文:

在那里你可以找到关于你的问题的例子和教程

你也可以像这样设置动作条的背景

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

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

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