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